home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-22 | 146.3 KB | 4,784 lines | [TEXT/MPS ] |
- /*
- File: RlShell.cpp
-
- Contains: Shell implementation
-
- Owned by: Nick Pilch
-
- Copyright: © 1993 - 1996 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <12> 4/4/96 NP 1338241: If shell is in infinite loop,
- quit.
- <11> 4/2/96 RA 1320667: Call
- Activate/DeactivateFrontWindows around
- ShowAboutScreen modal dialog call
- <10> 3/29/96 DM 1334273: propagate fatal Bento errors and
- show low mem alert and quit when
- out-of-memory err occurs while trying to
- show low memory alert (solving infinite
- loop).
- <9> 3/22/96 CC 1307182: UpdateMenus: Check for null edit
- menu.
- <8> .03.1996 NP 1307182: Stuff for caching shell menu
- items.
- <7> 3/20/96 EL 1331460 Save a Copy does not include the
- resources in parent document (e.g.
- preferred memory size)
- <6> 3/14/96 NP 1287354: Hide invisible files in the Open
- Document dialog.
- <5> .03.1996 NP 1223399: Don't show error dialog while
- suspending.
- <4> .03.1996 NP 1304875,1317218: Fix can't-cancel problem
- on receipt of quit event.
- <3> 3/1/96 JP 1314798: Made new documents run from temp
- file
- <2> 1/4/96 eeh 1302569: handle fat plugins
- <208> 10/26/95 TÇ 1296574 GM:Cannot set default memory
- partition size.
- <207> 10/25/95 TÇ 1295281 GM: Stationery not behaving
- properly.
- <206> 10/24/95 jpa 1293441: Beefed up error dialog and fg/bg
- detection. Moved mem stuff to new
- ShellMem.cpp.
- <205> 10/22/95 TÇ 1291419 GM: File type set incorrectly for
- Old Mac data dragged to Finder from
- OpenDoc.
- <204> 10/18/95 CC GM 1290956: Do not display alert if
- ExportClipboard fails during suspend event.
- <203> 10/18/95 eeh 1287095: exception safety
- <202> 10/16/95 CC GM 1292157: GetThisKindFromList returns
- ODType instead of void.
- <201> 10/13/95 TÇ 1284461 GM: Parts that are created in a
- document should not automatically be given
- names
- <200> 10/4/95 jpa Don't throw exceptions from ExceptionAlert,
- and don't check low memory on suspend evt
- [1289074]
- <199> 10/3/95 TJ Added Includes so it compiles
- <198> 9/29/95 eeh 1287262: use ShellDef.h
- <197> 9/28/95 JP 1287110: Made Save As dialog Stationery
- button work correctly
- <196> 9/27/95 TÇ 1287338 GM: ODOpenDraft returns with
- incorrect refcount on draft if it's not
- read-only
- <195> 9/27/95 eeh 1284464: use ClipStringToBytes; 1284893:
- fix capitalization
- <194> 9/26/95 TÇ 1287296 GM:Refcount error and eventual
- crash saving across volumes
- <193> 9/26/95 eeh 1284893: add and use BITTEST
- <192> 9/20/95 TÇ 1284568 GM: Choosing cancel in Save As...
- dlg closes doc.
- <191> 9/20/95 eeh 1284893: need TRY around SetErrorCode
- <190> 9/19/95 eeh 1284893: don't close connection to plugin
- unless told to
- <189> 9/13/95 VL 1283523: Dragging parts between Documents &
- Finder needs to reflect new behavior
- <188> 9/13/95 TJ Removed the #include for the Shell
- Plugins.xh
- <187> 9/13/95 TÇ 1280629 FB1: *OpenDoc crashes allocating
- memory to display alert for out of memory!
- <186> 9/12/95 JBS 1282526 Status message needed during "Save
- Doc to another volume"
- <185> 9/12/95 eeh 1283557: don't call IsCommandRegistered
- <184> 9/12/95 TÇ 1270499 FB1: OpenDoc launcher creates
- bogus document for old style documents
- <183> 9/12/95 eeh 1253309: change name of symbol sought to
- ODShellPluginInstall
- <182> 9/12/95 eeh 1283557: call IsCommandRegistered; 1253309:
- ScanShellPlugInsFldr changes for plugins
- <181> 9/11/95 TÇ 1252120 FB1: New documents saved w/ StdFile
- & trashed if closed w/o saving
- <180> 9/11/95 NP 1272294: Messaging code cleanup.
- <179> 9/8/95 TÇ 1252120 FB1: New documents saved w/ StdFile
- & trashed if closed w/o saving
- <178> 9/8/95 jpa Don't display error kODErrAlreadyNotified.
- [1278813]
- <177> 9/8/95 TÇ 1281096 FB2:Many constants in ODTypesB
- without kOD prefix!
- <176> 9/8/95 TÇ 1282092 FB2: Shell must check nil after SOM
- new
- <175> 9/7/95 eeh 1278987: use UniquifyName
- <174> 9/7/95 CG #1270499 FB1:OpenDoc launcher creates bogus
- document
- <173> 9/7/95 EL 1281410: Window for draft just above a
- deleted draft will not be automatically
- closed when that draft is deleted.
- <172> 9/6/95 VL Fixed build for MW.
- <171> 9/6/95 TJ Fixed build for scpp.
- <170> 9/5/95 TÇ 1280334 Shell's Save menu item available
- even on locked documents, 1276297 FB1:
- Save As dialog's Kind popup doesn't handle
- Translate To correctly, FBs: 1266428,
- 1274419, 1274421, 1274423, 1274429, 1274435
- Fixed the Shell to handle multiple
- documents in a process. Needed for
- CyberDog.
- <169> 8/31/95 DM 1273863, 1275336: ODClipboard::DraftSaved
- <168> 8/26/95 TÇ 1273606 FB: SemtIntf should delete
- _fHelper,1279063 FB3: must check results
- of SOM operator new
- <167> 8/25/95 JP 1262410: Update comments on Open &
- ODGetIconFamily takes frame
- <166> 8/25/95 eeh 1263528: revert to using
- fOptionKeyDownOnMenuBarClick
- <165> 8/22/95 eeh 1276821; 1276281: menu changes; 1263528:
- handle cmd-option-keys; 1267136: change
- menu ids
- <164> 8/17/95 eeh 1272319: in RealShell::Open, don't null out
- fDraft and release rootPart
- <163> 8/15/95 TÇ 1261899 DocUtils getters should be renamed
- Acquire___ , 1262179 FB: Shell calls
- BlockMove() in many places , 1256049 FB:
- Silent quit caused by exception in
- RlShell::Open, 1260378 MouseEvents in
- non-OpenDoc windows do not get dispatched
- if...
- <162> 8/15/95 CC 1275241: Added #include of Editons.h.
- <161> 8/13/95 TÇ 1259154 FB: Extra &'s in
- ScanShellPlugInsFolder function in
- RlShell.cpp
- <160> 8/12/95 TÇ 1276812 Need to use TempObjs and TempRefs
- for exception safety and to avoid TRY
- blocks, 1276807 Opt./Bug: use StdTypIO
- routines for portable streaming & smaller
- footprint
- <159> 8/8/95 TJ Declared FindObjsProc extern C
- <158> 8/8/95 jpa Document file synchronization &
- notification support [1259401]. Display app
- heap info in addition to OD heap; remove
- system heap [1262722]
- <157> 8/7/95 TJ Typecast &FindObjsProc to (MMBlockInfoProc)
- for the MMWalkHeap call so it will compile
- with SCpp.
- <156> 8/4/95 DM 1270320: mem leaks, 1267956: leak-detect
- tool; new menu items for tracking stack
- crawls, dumping tracked blocks, dumping on
- close; watch keyboard on launch (and during
- dump) to enable tracking (and filter out
- NewClass); consolidate crawls in dump
- <155> 8/2/95 VL 1270320: Release baseMenuBar after creating
- it.
- <154> 7/28/95 VL 1270320: Don't call DraftSaved when the
- draft is not opened. Use TempPlatformFile
- in SaveACopy. Dispose of fSaveCopyData
- fields and editorID in AskUserWhereToPutIt.
- <153> 7/25/95 DM #1270320: Memory leak fixes.
- <152> 7/25/95 VL 1270320: Dispose rootPartType in New.
- <151> 7/24/95 CG #1270320: Memory leak fixes.
- <150> 6/30/95 TÇ 1264094 BB:Custom document size cannot be
- attached to a stationery.
- <149> 6/29/95 eeh 1263784: add and use SendFinderODOCEvent
- <148> 6/28/95 RR 1242642 BB Mostly ref counting
- <147> 6/28/95 CG 1263107 BB: No more crash when closing a
- NoPart document.
- <146> 6/25/95 TÇ 1242642 BB: Turn on ODDebug warning if
- refcount is wrong in
- ODRefCntObjectsomUninit.
- <145> 6/21/95 JBS turn on mem validation
- <144> 6/21/95 CC 1260937: BB: ODTypeListIterator must return
- copies of ODType values.
- <143> 6/20/95 TÇ 1217754 BB: Delete Document command 1234877
- BB: OpenDoc creates a bad document if
- stationary launch fails.
- <142> 6/16/95 CC 1257141: InitKindsPopup: Pass kODNULL as
- translateFromList parameter to
- GetDestinationKindsList.
- <141> 6/15/95 NP 1237542: Fix CORBA memory stuf
- <140> 6/15/95 RR #1256879 Get->AcquireCurrentMenuBar
- <139> 6/8/95 RR #1257260 Collapse base classes. #1214898
- StdTypes.r -> ODTypes.r
- <138> 6/7/95 TÇ 1241521 Save a Copy of read only document
- ends up in temp folder. Fixed for newly
- created documents as well.
- <137> 6/2/95 TÇ 1253327 BB: Creating Stationery will drop
- it onto desktop. Now created in proper
- location
- <136> 6/2/95 TÇ 1216915 BB:Trying to open a document that
- is already open causes an error.
- <135> 6/1/95 jpa ExceptionAlert displays msg in programmer
- alert box. [1242839]
- <134> 5/26/95 RR #1251403: Multithreading naming support
- <133> 5/25/95 jpa Fixed GetKeys call for univ hdrs 2.0
- [1241078, 1253324]
- <132> 5/21/95 TÇ 1249149 BB: Crash when opening huge
- document
- <131> 5/20/95 TÇ 1211170 Two launches to open. Fixed
- Stationery creation so that it creates
- stationery on the desktop if you have no
- Stationery folder.
- <130> 5/19/95 TÇ 1155852 BB: String constants need to be
- moved to resource for Localization, 1249396
- (was BB) OpenDoc shell should serialize
- stationery creation., 1234877 BB: OpenDoc
- creates a bad document if stationary launch
- fails., 1211170 Two launches to open
- stationery
- <129> 5/18/95 eeh 1236414: pass hasWriteAccess to
- DraftWindow::Drafts()
- <128> 5/18/95 CG #1249263 BB: BndNSUtl.cpp does not compile
- standalone.
- <127> 5/17/95 RR #1250135/1250137/1250143 Getters increment
- refcount
- <126> 5/16/95 TÇ 1249181 Init methods should be private,
- Shell shouldn't call InitTypeList
- <125> 5/10/95 eeh 1232095: used DraftSaved; 1239830 :respond
- to kDraftWinLowMemAbort
- <124> 5/7/95 TÇ 1155852 BB: String constants need to be
- moved to resource for Localization (mostly
- done), 1246777 BB: Shell Plugin install
- method needs to pass fDraft not draft.,
- 1246539 Shell calls private window methods
- <123> 5/5/95 TJ ODDialogBegin is now passed the current
- Menu bar.
- <122> 5/4/95 eeh 1232095: set create date when saving (temp)
- <121> 5/4/95 jpa Check for low memory in event loop. Alert
- user [1235657] and call Purge [1221904].
- <120> 5/1/95 CG #1240845 BB: Kinds popups need to include
- all kinds that an editor can edit.
- <119> 5/1/95 CL Dialog fixes [1224714, 1228662, 1228678,
- 1229912].
- <118> 4/30/95 TÇ 1242084 BB - Operations should not be
- undoable across Save's
- <117> 4/29/95 TÇ 1216130 BB: Shell should open top draft
- upon receipt of open document Apple event
- <116> 4/28/95 NP 1236303: Remove ODGetSystemHeap and
- gSystemHeap.
- <115> 4/28/95 eeh 1240648: use AcquireActiveWindow in
- GetFrontDraft
- <114> 4/27/95 TÇ 1241327 BB: Bad problems option-closing
- child window (Not finished)
- <113> 4/27/95 eeh 1240648: add ODDraft* param to
- AskUserWhereToPutIt and SaveACopyAs; added
- GetFrontDraft
- <112> 4/27/95 CC 1243813: Removed MacAppAlert; use ShowAlert
- in DlogUtil instead.
- <111> 4/19/95 TÇ #1241116 DR/BB: Shell should externalize
- newdraft before getting root part kind.
- <110> 4/15/95 TÇ #1216915 DR/BB:Trying to open a document
- that is already open causes an error.
- <109> 4/14/95 TÇ #1186294 DR/BB: Binding for editor also
- affect making stationary
- #1239463 Save a copy does not work
- #1239933 BB: Save A Copy of a Read only
- document fails
- <108> 4/14/95 TÇ #1237984 RealShell::() UpdateMenus
- defaults part info menu item to wrong text
- #1235279 BB: InfoUtil & StdTypIO functions
- should take Environment* and SU* when
- possible
- <107> 4/14/95 NP 1237538: Don't call SetMenuItemScript
- anymore.
- <106> 4/13/95 CG #1221869 BB: Shell now looks for Shell
- Plug-Ins in the Shell Plug-Ins folder.
- <105> 4/13/95 TJ 68K Opening Stationary causes crash. Stack
- was getting corrupted. Fixed by JA
- <104> 4/10/95 TÇ #1234877 BB: OpenDoc creates a bad document
- if stationary launch fails.
- #1236210 BB: "Show Parts Bin" menu item
- must be removed from the Edit menu
- #1222541 BB: New document name
- #1226675 Option-Close does not close all
- Windows
- <103> 4/7/95 RR #1211085 Removed call to display base menu
- bar in OpenDraft
- <102> 4/7/95 eeh 1221297: added fPrintingOnly
- <101> 4/5/95 CG #1216169 BB, #1221135: When Editors folder
- or OpenDoc Libraries folder is missing,
- OpenDoc quits and displays error.
- <100> 4/4/95 RR #1226493 Call DisposeIText in UpdateMenus.
- <99> 3/31/95 TÇ 1196067 BB: Can resize a window so small
- that it disappears (Mostly fixed)
- 1204755 BB: Canceling save dialog when
- Restart is chosen doesn't work correctly
- 1223465 BB: Opening and creating documents
- under low disk space. (Creating documents
- under low disk space part fixed).
- 1211032 BB: Invalid Permissions error
- opening locked document
- <98> 3/29/95 NP 1233490: Use Mac system constant for
- international text stuff.
- <97> 3/28/95 CG #1221901 BB: Shell can now open
- non-OpenDoc documents.
- <96> 3/24/95 eeh 1229961: pass ev to some draftwindow
- methods
- <95> 3/24/95 CG #1221473 is really the bug number.
- <94> 3/24/95 CG #122143: Part API change for Doc/Part Info
- dialogs for viewers or readonly docs.
- <93> 3/22/95 RR #1225420, 122793 Fixed CloseWindow
- OpenDraft only calls OpenWindows if not
- already internalized. WindowList became
- RootFrameList
- <92> 3/21/95 TÇ Changed the rest of the #ifdef ODDebug to
- #if ODDebug. Also fixed #1227362
- Incorrect use of ODFinalReleaseObject.
- <91> 3/20/95 TJ Changed #ifdef ODDebug to #if ODDebug, and
- included "MemDebg.h".
- <90> 3/16/95 TÇ Also, #1190903 DocShell calls
- ODLinkManager::DraftSaved on Save a Copy..
- <89> 3/16/95 TÇ #1226090 BB: NonDebug DebugStrs in RlShell
- #1226375 Should not call NewRgn
- <88> 3/15/95 eeh 1194180: removed parameter from
- CloseDraft()
- <87> 3/10/95 CC 1225050: Call ODClipboard::DraftClosing
- instead of ExportClipboard when draft is
- closed; Call ExportClipboard from
- destructor.
- 1194180: CloseDraft shouldn't remove draft
- during iteration. [for eeh]
- <86> 3/7/95 RR # 1151165 Cleaned up UpdateMenus a bit
- <85> 3/6/95 jpa Use dialog utilities (ODGetNewDialog,
- ODDialogFilterProc). [1218957]
- <84> 3/1/95 RR #1205622 && #1164863 .CloseDraft removes
- draft from OpenDrafts list. Close open
- drafts in ::Close. OpenDraft doesn't call
- WS:Internalize if draft is open
- Register commands for shell menus (not
- items) Use private constants for
- Apple/Doc/Edit menu ids, since they're no
- longer in CmdDefs.idl
- <83> 2/23/95 EL 1220392: checking read only fails on file
- share volumes.
- <82> 2/20/95 TÇ #1210979 BB: 5-$ Bugs need to be evaluated
- and removed from Shell
- #1221861 BB: Incomplete AOCE support needs
- to be removed from OpenDoc
- <81> 2/16/95 TÇ #1210979 BB: 5-$ Bugs need to be evaluated
- in Shell. Fixed most of them, changed some
- to bug #'s.
- #1220906 Need ODFinalReleaseObject.
- <80> 2/15/95 NP 1220650: Use kOnSystemDisk to call to
- FindFolder.
- <79> 2/13/95 TÇ 1193359: BB: Opening stationery on other
- volume causes bus error in Messaging code
- 1211032: BB: Invalid Permissions Error
- opening locked document
- <78> 2/10/95 RR #1211187 Fixed bug in CloseWindow to
- support View In Window
- <77> 2/2/95 CG #1195019: ValueNameSpace entries are now
- copied in and out instead of pointers being
- passed around.
- <76> 1/27/95 TÇ 1196779 BB: Save a Copy with same name
- produces a program error
- 1207898 BB: DocShell exits on exception
- while processing OpenDoc apple event
- 1209735 Resolve 5-$ comments in
- PlfmFile.cpp
- <75> 1/26/95 eeh 1213354: ODActionData now an ODByteArray.
- <74> 1/25/95 jpa ODIText fixes. [1212619]
- <73> 1/25/95 RR #1211853 Removed session parameter from
- ODWindowState::CreateMenuBar
- <72> 1/23/95 CG #1195019: ValueNameSpace methods now take
- ODByteArray parameter instead of ODPtr.
- <71> 1/23/95 RR # 1211853 Use CreateMenuBar factory method
- <70> 1/19/95 TÇ #1209480 DocShell should change cursor when
- putting up dialogs
- #1210210 BB: API: ODShellPlugin::Install
- should take ODDraft*
- <69> 1/12/95 jpa Don't use obsolete Toolbox names. [1211211]
- Took out SCpp Pascal string workaround
- [1193085]
- <68> 1/4/95 eeh 1209163: enable menu commands in
- RealShell::UpdateMenus
- <67> 12/25/94 TÇ 1191189 Eliminate duplicate Def.h, Def.xh
- files
- 1187709 More frequent, robust and earlier
- error detection and reporting in the Shell
- <66> 12/21/94 eeh #1191567: release non-current draft when
- window closed; 1192626: force save after
- creating new draft
- <65> 12/20/94 VL 1195012: Make Storage calls be
- marshallable.
- <64> 12/19/94 eeh 1192626: DraftIsOpen and fOpenDrafts;
- change use of DraftWindow::Drafts()
- <63> 12/5/94 jpa Catch CFM errors opening new documents.
- [1158966]
- <62> 11/15/94 NP Added kludge to allow Object Master
- parsing.
- <61> 11/14/94 VL 1155887: Used new pos code for top draft.
- <60> 11/2/94 eeh #1154961: set document name in OpenFile.
- <59> 10/27/94 RR #1192168 Added CheckMenuBar to reinstall
- base menu bar when no part has the menu
- focus
- <58> 10/24/94 jpa Worked around scpp bug in InstallMenuBar.
- [1193085]
- <57> 10/11/94 eeh #1186849: change kODFileMenuID to
- kODDocumentMenuID
- <56> 10/10/94 NP 1192021-added new menu item.
- <55> 10/10/94 CC 1191567 - Release draft if root window of
- non-current draft is closed.
- <54> 10/7/94 TÇ #1187826 Document Info functionality &
- fixed saving/reverting/opening to use
- watch/arrow cursors correctly.
- <53> 9/29/94 RA 1189812: Mods for 68K build.
- <52> 9/26/94 TÇ #1188679 Save A Copy As Stationery
- <51> 9/23/94 VL 1155579, 1184272: Use StorUtil to
- create/get container and its file.
- <50> 9/22/94 NP 1187682: Added call to UseInputWindow.
- <49> 9/21/94 CG #1188048: Added check for NoPart.
- <48> 9/20/94 NP 1187682: Initial TSM support.
- <47> 9/19/94 TÇ #1176047 Multiple Windows (i.e. floating
- windows) are not deactivated when closing
- <46> 9/16/94 eeh #1186754: use a single document menu for
- OCE/no OCE cases
- <45> 9/15/94 TÇ #1183572 implement OpenDoc Shell PlugIns,
- and changes to support creating & opening
- stationery with ODTestMain by dropping
- editor library files on ODTestMain
- <44> 9/14/94 jpa Use new MemDebg API calls (OD-->MM)
- [1186692]
- <43> 9/9/94 jpa Fixed missing-prototype probs [1185658]
- <42> 9/8/94 eeh #1185443: changes to account for read-only
- files.
- <41> 9/2/94 eeh 1184782 Added check in ::New for container
- in tmp items folder
- <40> 9/2/94 eeh moved mailer-specific stuff to RlShlMlr.cpp
- in the process of fixing 1150934 and
- 1167302
- <39> 8/31/94 TÇ #1183129, #1183116, #1183119, #1183111:
- Lots of ErrorCode cleanup.
- <38> 8/29/94 TÇ #1183553 Need to reduce usage of ODFileSpec
- in RlShell
- <37> 8/26/94 TÇ #1158958 Watch cursor while saving
- #1181761 rename obsolete kOD IDs to correct
- kODStrong/WeakStorageUnitRefs
- #1155850 Can't resize a document large on
- larger monitors
- #1149697 Resize window to titlebar, move
- titlebar, window disappears
- <36> 8/26/94 VL 1183174: GetStorageUnitRef takes
- ODStorageUnitID now.
- <35> 8/25/94 TÇ #1183223 Enabled launching of documents in
- folders other than that of the OpenDoc
- libraries. Disabled WASSERT if System
- Process does not launch.
- <34> 8/22/94 TÇ #1182448 System Process quits when no
- OpenDoc documents are running
- <33> 8/19/94 jpa Stop calling ODInitMemory [1182106]
- <32> 8/19/94 TÇ #1180922 Need to Stop using obsolete types
- (kOD ID)
- <31> 8/17/94 jpa Added "Dump Objects" command to the debug
- menu, and enhanced the "Mem Info" dialog.
- [1179567]
- <30> 8/15/94 JBS 1181156: UI API Cleanup
- <29> 8/15/94 TÇ #1180922 Removed most obsolete types from
- StdTypes.idl
- <28> 8/12/94 NP 1180762-session->close to delete session.
- <27> 8/11/94 eeh add ShellMain function
- <26> 8/10/94 JBS 1179919: coordinate system bias changes
- <25> 8/8/94 jpa Added "Heap Info" cmd to ODDebug menu.
- [1179567]
- <24> 8/3/94 VL Temporarily commented out system process
- stuff.
- <23> 8/3/94 CC ExportClipboard() - removed calls to lock
- and unlock; MUST FIX TO REQUEST CLIPBOARD
- FOCUS (currently a frame is required but
- none is available).
- <22> 8/3/94 VL 1153123: Storage to ODStor.
- <21> 8/2/94 jpa Added "Break on THROW" to ODDebug menu.
- <20> 8/2/94 TÇ #1178167 Enabled code to launch System
- Process if it had not already been
- launched.
- <19> 8/1/94 TÇ cleaned up launcher code, added code to
- check for and launch System Process
- <18> 7/29/94 CG NameSpace API changes.
- <17> 7/28/94 TÇ fixed a comment
- <16> 7/27/94 jpa Added the ODDebug menu.
- <15> 7/27/94 NP Fixed Undo and About menu code.
- <14> 7/26/94 jpa Took out old commented-out memory
- validation calls; moved these to Shell.cpp.
- <13> 7/26/94 eeh Pass Point to ODWindow::Drag by reference
- <12> 7/21/94 TÇ fixed New to workaround lack of binding
- implementation, eliminated another
- STATICBUILD reference, fixed Open to set
- the name of the root part correctly
- <11> 7/21/94 eeh fix installation of AOCE menu
- <10> 7/21/94 TÇ took out STATICBUILD, DONTOPENANOTHERFILE
- symbols, put in special case code for
- ODTestMain to use a single process instead
- of launching another one when opening
- stationery, moved SOM_Trace enablement to
- the about box.
- <9> 7/19/94 TÇ properly disabled OpenAnotherFile for now
- <8> 7/14/94 TÇ added DetachResource(appleMenu);
- <7> 7/14/94 TÇ use document->Exists(fDraft) instead of
- TRY/CATCH with AcquireDraft
- <6> 7/14/94 TÇ removed references to ASLMBILD
- <5> 7/13/94 TÇ removed some XMPs
- <4> 7/11/94 TÇ enabled calls to InfoUtil functions
- <2> 6/27/94 TÇ fixed includes
- <1> 6/27/94 TÇ first checked in
- <0> 6/17/94 SV SOMverted
- <35> 5/27/94 jpa New exception support [1165267]
- <34> 5/10/94 TÇ #1162405 Removed explicit ASLM dependency
- for using resources
- <33> 5/9/94 MB #1162181: Changes necessary to install MMM.
- <32> 4/27/94 TÇ #1159972: Fixed setting the FInfo type of
- OpenDoc Documents
- <31> 4/19/94 TÇ #1158391: Editor Setup part didn't always
- open. Whenever there is an empty
- windowstate, this fix explicitly tells the
- root part to open.
- <30> 4/18/94 TÇ #1157689: Clicking Zoom box was crashing
- due to not setting the port correctly.
- <29> 4/18/94 TÇ #1144379 Stationery model & generation have
- been fixed to enable dragging & dropping of
- stationery onto open documents.
- <28> 4/11/94 TÇ #1155854 Use CustomPutFile for Save A Copy.
- <27> 4/7/94 TÇ fixed #1155956
- <26> 4/1/94 TÇ #1154941: Get OpenDoc source to actually
- compile for PowerPC
- <25> 3/31/94 eeh bug #1154688: add !fAOCEFile test before
- Save() call in Open()
- <24> 3/28/94 CG 1153547: Renamed XMPSessn.h to XMPSessM.h
- <23> 3/27/94 TÇ #1153527 sync name of document & name of
- rootpart. enable renaming of document by
- changing name of root part in Part Info
- dialog.
- <22> 3/25/94 CC PPCNative: Removed inline assembly (for
- Tantek) (1153053); Change name of included
- file to <LinkMgr.xh>. (1153348)
- <21> 3/25/94 JA Hide some ODUnused calls from Metrowerks
- since they were causing problems for the
- compiler. (1153437)
- <20> 3/25/94 MB Symantec ASLM fixes. #1150864
- <19> 3/24/94 TÇ (no bug# yet) Stationery now just tears off
- instead of tearing off and opening.
- Cleaned & removed fIsNew flag, SaveAs()
- code, and someother #ifdef TO_BE_DELETD
- stuff
- <18> 3/17/94 CG #1151392: Moved kOpenDocShellSignature from
- ContsDef.h to StdDefs.h
- <17> 3/16/94 RR #1144764 Close doesn't close floaters
- anymore.
- <16> 3/16/94 eeh bug #1149649: added params to
- OpenAnotherFile; fleshed out ReplyToMail
- <15> 3/15/94 MB Changes to support SCpp/ASLM builds,
- #1150864.
- <14> 3/10/94 eeh bug #1149754: kHighLevelEvent case in
- DispatchEvent; #1149649: implement
- ForwardMail
- <13> 3/3/94 TÇ fix #1148389
- <12> 3/2/94 TÇ fixed #1147894
- <11> 2/28/94 CG TC: fixed crash in static build when
- opening a new stationary file.
- <10> 2/25/94 TÇ comment out the XMPMemValidation stuff
- <9> 2/24/94 TÇ fix #1145435. Save and Revert to Saved
- menu items are now enabled properly (only
- when there are changes to a draft) brand
- new documents which have never been saved
- are deleted when closed. cleaned up a few
- more comments.
- <8> 2/23/94 VL Moved memory error handling code from
- Main.cpp to ::go.
- <7> 2/17/94 TÇ fix to help #1144379, enable opening
- documents which were created by dragging
- from an OpenDoc document to the desktop.
- Make sure that a reference to the rootpart
- is written to the draft properties
- storageunit when the rootpart is created.
- Set the TYPE of stationery which is created
- by ODTestShell correctly.
- <6> 2/17/94 TÇ fix #1144404,#1144410, set stationery bit
- when creating stationery in ODTestShell,
- cleaned up SSREMOVEWORKAROUND
- <5> 2/16/94 TÇ fix #1144026
- <4> 2/16/94 JA Made SystemSupportsAOCE a static function.
- Include new AltPoint.h.
- <3> 2/16/94 TÇ #1144029 and remove some unnecessary
- #includes
- <2> 2/15/94 TÇ fix #1144029 and some cleanup
- <112> 2/8/94 TÇ Throw -> THROW & some code clean up
- <111> 2/7/94 JA Utilities.h --> XMPUtils.h
- <110> 2/7/94 TÇ more fixes to compile with PPC Headers
- <109> 2/4/94 TÇ fixes to compile with PPC Universal headers
- <108> 2/2/94 RR Call SetDefaultWindowTitles in ::Open
- <107> 2/2/94 TÇ added CreateUntitledContainer, changes to
- ::New and ::Open and ::OpenFile to enable
- proper creation of staionery in the static
- build, and proper opening of stationery in
- the dynamic build.
- <106> 1/31/94 NP Made coercion handler conform to new
- interface.
- <105> 1/28/94 RR Reorganized CloseWindow for multiple drafts
- <104> 1/28/94 TÇ got rid of a warning
- <103> 1/27/94 RR Disabled flag, so that parts now create
- initial window
- <102> 1/25/94 EL ISOStr includes the zero terminator.
- <101> 1/25/94 RR Create window invisible
- <100> 1/25/94 NP TÇ: added support for Draft Dialog, Create,
- Remove, Open Drafts. Fix for ASLM: error
- strings in exception dialog were not being
- displayed. NP: Implemented error catching
- for opendocs and openapp handlers.
- <99> 1/24/94 SS Docs created now have correct filetype
- <98> 1/24/94 NP Made dismissal of About Box work better.
- <97> 1/22/94 CC CloseWindow: Call ExortClipboard() before
- CloseDraft() to avoid potential problem;
- this sometimes avoids crashing but not
- always.
- <96> 1/21/94 eeh cleanup, part of which fixes mailer saves
- <95> 1/21/94 RR Added shouldSave to CreateWindow. Restored
- Dispatch() signature
- <94> 1/21/94 CC Added calls to ODLinkManager::DraftOpened,
- ::DraftSaved, and ::DraftClosing; conform
- to clipboard locking interface.
- <93> 1/21/94 CG Changed kPlatformFileContainer to
- kODDefaultFileContainer.
- <92> 1/20/94 SS Documents are now created/saved with the
- right file type/creator
- <91> 1/20/94 RR Moved AOCE Mailer stuff to StdDisp and
- WinState
- <90> 1/20/94 TÇ Added selection of rootpart in static
- build, fixed references to name of document
- in Revert and Close dialogs.
- <89> 1/19/94 NP Added call to ClearActionHistory when
- document is reverted or closed.
- <88> 1/19/94 eeh added Open Document menu item
- <87> 1/18/94 CG Changed kODBentoFileContainer to
- kPlatformFileContainer, include StorgDef.h.
- <86> 1/18/94 TÇ use kOpenDocShellSignature, and get rid of
- some obsolete constants
- <85> 1/17/94 NP Semantic Events callbacks API changes.
- <84> 1/15/94 RR WinState.h->WinStat.h,
- Dispatch.h->Disptch.h
- <83> 1/15/94 RR Updated HandleMenuEvent (command no. is no
- longer in event)
- <82> 1/14/94 TÇ implemented calls to DraftWindow to show
- Drafts Dialog, and to initialize the draft
- properties of a newly created draft
- <81> 1/14/94 CC ExportClipboard(): Use clipboard keys.
- <80> 1/13/94 eeh integrate AOCEObj; cosmetic changes
- <79> 1/13/94 NP Mods for Undo menu.
- <78> 1/12/94 CG Removed ODNewPtrClear - it's in ODMemory.cp.
- <77> 1/12/94 RR Call window->CloseAndRemove
- <76> 1/11/94 eeh fix user cancel exceptions and make mailer
- menu heierarchical
- <75> 1/10/94 NP Mods for the Undo and Redo menu items.
- <74> 1/6/94 TÇ commented out a few ODDisposePtr where a
- ptr allocated using NewPtrClear was being
- improperly disposed.
- <73> 12/22/93 RR Call Activate/DeactivateFrontWindows around
- modal dialog calls
- <72> 12/21/93 VL Changed ODStorageUnit::GetValueSize to
- StorageUnit::GetSize.
- <71> 12/21/93 JBS create frames with viewType and
- presentation
- <70> 12/20/93 VL Used WindowState to CreateWindow.
- <69> 12/20/93 RR Use new Init method for menu bar
- <68> 12/17/93 TÇ add some code for New and Open...
- <67> 12/17/93 TÇ remove Pre & Postflight around the main
- entry point (fEV,::go) and put them only where
- necessary around calls to GetResource or
- calls which call GetResource. Enable
- Multiple documents to be opened in the
- dynamically linked build.
- <66> 12/16/93 TÇ CreatePart changes, write out current
- Editor when user chooses New, read it in
- when opening a New'd document.
- <65> 12/13/93 RR Register command for About…. Set Item
- string to "About OpenDoc" in UpdateMenus in
- case active part doesn't
- <64> 12/12/93 TÇ added failure handling around Initialize
- <63> 12/9/93 eeh added params to Save, Close and others to
- support AppleEvents.
- <62> 12/9/93 VL Used ODQDGlobals instead of qd. Now we
- can drag windows around!
- <61> 12/3/93 CC Call ODClipboard::ExportClipboard on
- suspend events and when document is closed.
- <60> 12/1/93 VL Used new ODWindow calls that support
- floating windows.
- <59> 11/22/93 SS Added typecasts for latest headers
- <58> 11/19/93 RR Let dispatcher deal with plain command keys
- (i.e. no option, shift etc.)
- <57> 11/18/93 eeh fixed CreateTempFileSpec to avoid dup file
- names
- <56> 11/16/93 RR Call windowstate::AdjustPartMenus
- <55> 11/16/93 EL Use OpenDoc instead of Amber.
- <54> 11/16/93 RR Completely reorganized event-handling
- <53> 11/15/93 eeh changed SaveAs to just moveandrename the
- temp file, and added ManageMailerSave()
- <52> 10/29/93 RR MenuBar: EnDisable -> Enable
- <51> 10/28/93 TÇ added code to use the resource fork of
- ShellLibASLM in ASLM builds
- <50> 10/27/93 eeh rewrote CopyFiles not to use exceptions
- <49> 10/27/93 eeh More widespread changes to enable opening
- amber letters, particularly in
- GetFSSpecFromLetter() and CopyFile().
- <48> 10/26/93 PH Ignore error from FSpGetInfo in AECoerce
- handler
- <47> 10/22/93 PH Move manager inits to main
- <46> 10/21/93 RR CloseWindow uses new WindowState calls to
- detect "last" window. CreateWindow takes
- new flags
- <45> 10/21/93 TÇ fix CloseDraft() to NOT call
- WindowState->Externalize and
- fDraft->SaveToPrev
- <44> 10/20/93 eeh fixed problems with non-AOCE machines
- <43> 10/20/93 eeh Added coercion handler for incomming AOCE
- documents (fEV,alias->FFSpec). Incomplete.
- <42> 10/18/93 TÇ moved call to InitLibraryManager() from
- RealShell::Intialize to main(), reduced
- entrypoints into RealShell object to one.
- <41> 10/14/93 RR Use command numbers from CmdDefs.h
- <40> 10/14/93 JA ODShape fu: No longer returns copies from
- GetPlatformShape. Deal w/it.
- <39> 10/12/93 eeh More mailer support, and fixed problem with
- menu installation.
- <38> 10/8/93 TÇ fixed MPW compiler problems
- <36> 10/8/93 VL Call Release on ODPersistentObjects and
- ODStorageUnits.
- <35> 10/8/93 TÇ fixed Save A Copy to externalize only if
- there are changes
- <34> 10/8/93 RR Use IsODWindow
- <33> 10/8/93 TÇ bifurcated Document menu into normal and
- AOCE versions
- <32> 10/7/93 RR Remove call to CloseWindows for now because
- we can't delete while iterating
- <31> 10/7/93 RR Call WindowState::CloseWindows and
- Draft::CreateWindow
- <30> 10/7/93 TÇ Save A Copy uses name of file, comment out
- RemoveAOCEMailer call until it is moved to
- ODWindow::Close, fix size/location of
- window creation (copied some code from
- TeachText)
- <29> 10/7/93 eeh Various changes related to adding Mailer
- support, with more to come.
- <28> 10/4/93 TÇ added #ifdef SSREMOVEWORKAROUND until
- su->Remove(ev) is fixed
- <27> 10/4/93 RR Added hard-coded document title
- <26> 10/1/93 TÇ fixed file corruption
- <25> 10/1/93 TÇ fixed ErrRecord definition to use ODError
- and ODULong
- <24> 9/30/93 TÇ fixed smashing memory bug in New(), and
- Close/SaveAs() interaction bug
- <23> 9/29/93 TÇ got Revert() to work, auto New() on OAPP
- for now
- <22> 9/24/93 TÇ Integrated Storage System draft calls,
- enabled real implementation of Save, Close.
- With help from RCR: integrated the
- ODMenuBar object into the shell.
- <21> 9/24/93 JA Minor syntactic tweaks for THINK C++.
- <20> 9/23/93 TÇ fixed Error handling code so that it
- doesn't crash if there is no window
- <19> 9/22/93 NP Integrated Semantic Events into the
- DocShell.
- <18> 9/22/93 RR menuBar::Add -> AddLast(). Still need to
- modify menu handling code to use
- registered commands.
- <17> 9/15/93 TÇ implemented Error Handling
- <16> 9/10/93 RR Use new ODMenuBar interface
- <15> 8/27/93 TÇ implemented updated New, Open..., Open
- stationery, About...
- <14> 8/24/93 TÇ integrated with partial storage
- implementation, enabled readwrite access
- <13> 8/20/93 TÇ integrated with Prototype Window, Layout,
- Imaging and parts.
- <12> 8/19/93 TÇ release document & container when closing
- <11> 8/19/93 TÇ SS Integration: doc/window opens, closes &
- quits
- <10> 8/19/93 TÇ SS integration: got windowstate to
- internalize
- <9> 8/9/93 TÇ with help from CG: implement/integrate ODOC
- <8> 7/21/93 TÇ with help from CG: implement/integrate OAPP
- & QUIT AppleEvent handlers
- <7> 7/6/93 TÇ implement Draft Interface
- <6> 5/24/93 TÇ finish implementing methods for open, save,
- close, save as, revert
- <5> 4/30/93 TÇ implement Open
- <4> 4/29/93 TÇ change names of includefiles
- <3> 4/28/93 TÇ implement more Event Loop
- <2> 4/27/93 TÇ implemented Initialization, bare bones Main
- Event Loop
- <1> 4/14/93 TÇ first checked in
-
- In Progress:
-
- */
-
- #ifndef _PLFMDEF_
- #include <PlfmDef.h>
- #endif
-
- #ifndef _SHELLDEF_
- #include "ShellDef.h"
- #endif
-
- #ifndef _SHLMAIN_
- #include "ShlMain.h"
- #endif
-
- #ifndef _DOCUTILS_
- #include "DocUtils.h"
- #endif
-
- #ifndef _UTILDEFS_
- #include "UtilDefs.h"
- #endif
-
- #ifndef _RLSHELL_
- #include "RlShell.h"
- #endif
-
- #ifndef _SHPLUGIN_
- #include "ShPlugIn.h"
- #endif
-
- #ifndef _USERSRCM_
- #include <UseRsrcM.h>
- #endif
-
- #ifndef _EXCEPT_
- #include <Except.h>
- #endif
-
- #ifndef SOM_Module_OpenDoc_Commands_defined
- #include <CmdDefs.xh>
- #endif
-
- #ifndef _ODUTILS_
- #include <ODUtils.h>
- #endif
-
- #ifndef _BINDNGH_
- #include <BindngH.h>
- #endif
-
- #ifndef _BNDNSUTL_
- #include <BndNSUtl.h>
- #endif
-
- #ifndef _TEMPOBJ_
- #include "TempObj.h"
- #endif
-
- #ifndef _TEMPITER_
- #include "TempIter.h"
- #endif
-
- #ifndef _ODMEMORY_
- #include <ODMemory.h>
- #endif
-
- #ifndef _BARRAY_
- #include <BArray.h>
- #endif
-
- #ifndef SOM_ODDispatcher_xh
- #include <Disptch.xh>
- #endif
-
- #ifndef SOM_ODWindowState_xh
- #include <WinStat.xh>
- #endif
-
- #ifndef SOM_ODWindowIterator_xh
- #include <WinIter.xh>
- #endif
-
- #ifndef SOM_ODWindow_xh
- #include <Window.xh>
- #endif
-
- #ifndef SOM_ODMenuBar_xh
- #include <MenuBar.xh>
- #endif
-
- #ifndef _ORDCOLL_
- #include "OrdColl.h"
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODFrameFacetIterator_xh
- #include <FrFaItr.xh>
- #endif
-
- #ifndef SOM_Module_Apple_defined
- #include <Part.xh>
- #endif
-
- #ifndef SOM_ODArbitrator_xh
- #include <Arbitrat.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_Foci_defined
- #include "Foci.xh"
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODLinkManager_xh
- #include <LinkMgr.xh>
- #endif
-
- #ifndef SOM_ODStorageSystem_xh
- #include <ODStor.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODDocument_xh
- #include <Document.xh>
- #endif
-
- #ifndef SOM_ODContainer_xh
- #include <ODCtr.xh>
- #endif
-
- #ifndef SOM_ODClipboard_xh
- #include <Clipbd.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include <StdTypes.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef _ITEXT_
- #include <IText.h>
- #endif
-
- #ifndef _ISOSTR_
- #include <ISOStr.h>
- #endif
-
- #ifndef _PASCLSTR_
- #include <PasclStr.h>
- #endif
-
- #ifndef _STORUTIL_
- #include <StorUtil.h>
- #endif
-
- #ifndef SOM_ODUndo_xh
- #include <Undo.xh>
- #endif
-
- #ifndef SOM_ODInfo_xh
- #include <Info.xh>
- #endif
-
- #ifndef _DRAFTWN_
- #include "DraftWn.h"
- #endif
-
- #ifndef _ODPRCS_
- #include "ODPrcs.h"
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdDefs_defined
- #include <StdDefs.xh>
- #endif
-
- #ifndef _INFOUTIL_
- #include <InfoUtil.h>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StandardExtensions_defined
- #include <StdExts.xh>
- #endif
-
- #ifndef _STDTYPIO_
- #include <StdTypIO.h>
- #endif
-
- #ifndef _DLOGUTIL_
- #include <DlogUtil.h>
- #endif
-
- #ifndef _MEMMGR_
- #include <MemMgr.h>
- #endif
-
- #if ODDebug
- #ifndef _MEMDEBG_
- #include <MemDebg.h>
- #endif
- #endif
-
- #ifndef __QUICKDRAW__
- #include <QuickDraw.h>
- #endif
-
- #ifndef __STANDARDFILE__
- #include <StandardFile.h>
- #endif
-
- #ifndef __FOLDERS__
- #include <Folders.h>
- #endif
-
- #ifndef __FONTS__
- #include <Fonts.h>
- #endif
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
-
- #ifndef __OSEVENTS__
- #include <OSEvents.h>
- #endif
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef __PACKAGES__
- #include <Packages.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __DESK__
- #include <Desk.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __LOWMEM__
- #include <LowMem.h>
- #endif
-
- #ifndef __GESTALTEQU__
- #include <GestaltEqu.h>
- #endif
-
- #ifndef __SCRIPT__
- #include <Script.h>
- #endif
-
- #ifndef __FINDER__
- #include <Finder.h>
- #endif
-
- #ifndef __FILES__
- #include <Files.h>
- #endif
-
- #ifndef __ICONS__
- #include <Icons.h>
- #endif
-
- #ifndef __ALIASES__
- #include <Aliases.h>
- #endif
-
- #ifndef __TEXTSERVICES__
- #include <TextServices.h>
- #endif
-
- #ifndef __LIMITS__
- #include <limits.h>
- #endif
-
- #ifndef __STRING__
- #include <string.h>
- #endif
-
- #ifndef SOM_ODPartWrapper_xh
- #include "PartWrap.xh"
- #endif
-
- #ifndef __STDIO__
- #include <stdio.h>
- #endif
-
- #ifndef __SEGLOAD__
- #include "SegLoad.h"
- #endif
-
- #ifndef _ODDEBUG_
- #include "ODDebug.h"
- #endif
-
- #ifndef _MEMMGR_
- #include "MemMgr.h"
- #endif
-
- #ifndef _MEMDEBG_
- #include "MemDebg.h"
- #endif
-
- #ifndef _STORUTIL_
- #include <StorUtil.h>
- #endif
-
- #ifndef _NMSPCUTL_
- #include <NmSpcUtl.h>
- #endif
-
- #ifndef SOM_ODBinding_xh
- #include <ODBindng.xh>
- #endif
-
- #ifndef SOM_ODTranslation_xh
- #include <Translt.xh>
- #endif
-
- #ifndef SOM_ODTypeList_xh
- #include <TypeList.xh>
- #endif
-
- #ifndef SOM_ODTypeListIterator_xh
- #include <TypLsItr.xh>
- #endif
-
- #ifndef _SIHELPER_
- #include <SIHelper.h>
- #endif
-
- #ifndef _EDITRSET_
- #include <EditrSet.h>
- #endif
-
- #ifndef _TRANSUTL_
- #include <TransUtl.h>
- #endif
-
- #ifndef _CRAWL_
- #include <Crawl.h>
- #endif
-
- #ifndef _SEUTILS_
- #include "SEUtils.h"
- #endif
-
- #ifndef __EDITIONS__
- #include <Editions.h>
- #endif
-
- #ifndef __CODEFRAGMENTS__
- #include <CodeFragments.h>
- #endif
-
- #ifndef _CONSTDEF_
- #include <ConstDef.h>
- #endif
-
- #ifndef _SHELLMEM_
- #include <ShellMem.h>
- #endif
-
- #pragma segment RealShell
-
- #if ODDebug
- //==============================================================================
- // Debugging #Defines
- //==============================================================================
-
- #endif
-
- //==============================================================================
- // Constants
- //==============================================================================
-
- // <eeh> this should be defined elsewhere, so that parts like EditorSetup can
- // use it rather than risk choosing another constant.
- const ODMenuID kODAppleMenuID = 255;
- const ODMenuID kODDocumentMenuID = 256;
- const ODMenuID kODEditMenuID = 257;
- const ODOSType kODDASMenuRsrc = 0x44525652; // 'DRVR';
-
- const ODSLong kMaxTimeBetweenLocationChecks = 3 * 60L; // Background file check delay
-
- const short kMaxUniqueNameTries = 100;
-
-
- const ODSShort kUseSpecificScript = 0x1c;
-
- #define kMaxNumberSuffixLength 11
-
- // For window resizing
- #define kMinWindowWidth 192
- #define kMinWindowHeight 64
- #define kMaxWindowWidth 16384
- #define kMaxWindowHeight 16384
-
- // from DrawDef.h
- #define kODKindTestDraw "Apple:Kind:TestDraw"
-
- // Local error codes:
-
- #define kODErrClosingNonODWindow 5001
-
-
- #define ODDebugMenu ODDebug /* Use Debug menu if debug build */
-
-
- #if ODDebugMenu
- const ODMenuID kDebugMenuID = 100;
- // Command IDs for the debugging menu:
- enum {
- kODCommandDBHeapInfo = 980,
- kODCommandDBDumpObjects,
- kODCommandDBDumpBlocks,
- kODCommandDBMemValidation,
- kODCommandDBHeapChecking,
- kODCommandDBLeakChecking,
- kODCommandDBDumpBlocksOnClose,
- kODCommandDBTrackStackCrawls,
- kODCommandDBLogStdout,
- kODCommandDBLogDebugWindow,
- kODCommandDBLogDebugStr,
- kODCommandDBSOMTrace,
- kODCommandDBBreakOnThrow,
- kODCommandDBEatMemory,
- kODCommandDBPurge
- };
-
- const short kODHeapInfoAlert = 980;
- #endif
-
- const StringPtr kODEmptyPString = "\p";
-
- //==============================================================================
- // Local Macros
- //==============================================================================
-
- #if ODDebug
- #define SHLDebugStr(x) DebugStr(x)
- #else
- #define SHLDebugStr(x)
- #endif
-
- #define BITTEST( codes, thisCode ) \
- (((codes) & (thisCode)) != 0L)
-
- //#define SHLHeapDebug
- //#define SHLTestSessionOverhead
- //#define SHLTestErrorDialogUsage
-
- //==============================================================================
- // Static variables
- //==============================================================================
-
- #if ODDebug
- static ODBoolean gMemValidation = kODFalse;
- static ODBoolean gHeapChecking = kODFalse;
- static ODBoolean gLeakChecking = kODFalse;
- static ODBoolean gDumpBlocksOnClose = kODFalse;
- static ODBoolean gTrackStackCrawls = kODFalse;
- #endif
-
- #ifndef __MWERKS__
- QDGlobals qd;
- #endif
- // Need to declare 'qd' ourselves because even though 'qd' is already
- // in Startup.c in the Metrowerks libraries, it is NOT necessarily in the
- // libraries for other compilers, e.g the compilers for CFM68K. -TÇ
-
- //==============================================================================
- // Local Classes
- //==============================================================================
-
- struct ErrRecord
- {
- ODError lowErr, highErr;
- ODULong index;
- };
-
- typedef ErrRecord* ErrRecordPointer;
- typedef ErrRecordPointer* ErrRecordHandle;
-
- //==============================================================================
- // Function Prototype
- //==============================================================================
-
- void CreateTempName(short seed, Str255 name, ODBoolean isFile);
- // $opt: CreateTempName is duplicated in ODPrcs.cpp
-
- void GetTempFolder(ODSShort* VRef,ODSLong* DirID);
- void CreateNewFile(PlatformFile* newFile, ODBoolean forceNewName); // newFile is in/out
-
- pascal void DrawSmallIcon(DialogPtr theDialog, short theItem);
- pascal short SaveCopyDlgHook(short item, DialogPtr theDialog, void *yourDataPtr);
-
- static ODBoolean isOptionKeyDown();
-
- #if ODDebug
- static ODBoolean isHeapKeyDown();
-
- static ODBoolean isFilterKeyDown();
-
- static void HeapInfo();
-
- #endif
-
- ODStatic void InitKindsPopup ( ODTypeList* kindList,
- ODType theKind,
- ControlHandle itemHandle,
- ODSShort* currentKindItem,
- MenuHandle kindMenu,
- ODSShort* translateItem,
- ODSession* session );
-
- ODStatic void FindShellPlugInsFolder(short *vol, long *dir );
- ODStatic void FindStationeryFolder(short *vol, long *dir );
-
- ODStatic void CreateNewUntitledFile(PlatformFile* newFile,
- char* fileNameSeed = kODNULL);
- // Note: fileNameSeed is ignored if newFile->IsStationery()
-
- static ODIText* CreateDefaultIText(StringPtr text);
- static OSErr SendFinderODOCEvent( const FSSpec *fileToOpen );
- ODStatic OSErr GetCfrgInfo( ODFileSpec* fileSpec, long* offset, long* length );
- ODStatic void CopyResources(PlatformFile* srcFile, PlatformFile* dstFile);
-
-
- extern ODBoolean gODBentoFatalErrorHasOccurred; // SessHdr.cpp
- extern ODBoolean gODDelayBentoFatalError; // SessHdr.cpp
- extern ODBoolean gODSuppressBentoFatalError; // SessHdr.cpp
- extern void ODBentoFatalError(); // SessHdr.cpp
-
- #if ODDebug
- static void DumpHeapObjects( ODBoolean objectsOnly );
- #endif
-
- //==============================================================================
- // ShellMain Function
- //==============================================================================
-
- #pragma lib_export on // only ShellMain needs to be exported
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
- int ShellMain()
- {
- MaxApplZone();
- MoreMasters();
- MoreMasters();
- MoreMasters();
- MoreMasters(); // $Opt: May need more of these. Poke about at runtime to see.
-
- InitGraf(&qd.thePort);
-
- InitFonts();
- FlushEvents(everyEvent, 0);
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(kODNULL);
- WatchCursor();
-
- /* Note below that we continue even if the Edition Manager or TSM are not around.
- There is no express reason that either one of these need to be around for OpenDoc
- in general to function. Lack of Edition Manager just means you can't do linking.
- */
-
- if (InitEditionPack() != noErr)
- SHLDebugStr("\pInitEditionPack failed");
-
- long gestaltResponse;
- ODBoolean hasTSM = (Gestalt(gestaltTSMgrVersion, &gestaltResponse) == noErr) &&
- (gestaltResponse >= 1);
- if (hasTSM)
- {
- if (InitTSMAwareApplication() == noErr)
- {
- const TSMDocumentID kAnyDoc = kODNULL;
-
- if (UseInputWindow(kAnyDoc, kODTrue) != noErr)
- SHLDebugStr("\pUseInputWindow failed.");
- }
- else
- {
- SHLDebugStr("\pInitTSMAwareApplication failed.");
- }
- }
- else
- {
- SHLDebugStr("\pTSM unavailable.");
- }
-
- TRY
- ODInitExceptions(); // Sets up SOMError and SOMPrintf
-
- #if ODDebug
- MMBeginMemValidation();
- gMemValidation = kODTrue;
- #endif
-
- #if VALIDATE_EVERYTHING
- // MMBeginMemValidation(); Should be taken care of by above.
- MMBeginHeapChecking( );
- #endif
-
- if (isOptionKeyDown())
- SHLDebugStr("\pAbout to create and enter the Shell. You may proceed.");
-
- #if ODDebug
- if (isHeapKeyDown())
- {
- SHLDebugStr("\pAbout to track heap block stack crawls. Type g to proceed.");
- gDumpBlocksOnClose = kODTrue;
- gTrackStackCrawls = kODTrue;
- }
- #endif
-
- RealShell* le = new RealShell;
- le->go();
- delete le;
-
- #if VALIDATE_EVERYTHING
- MMEndHeapChecking( );
- MMEndMemValidation();
- #endif
-
- if (hasTSM)
- CloseTSMAwareApplication();
- CATCH_ALL
- /* Not much we can do here folks.
- Either ODInitExceptions failed, or creating a RealShell object failed.
- If the latter, then we don't have enough memory to put up a dialog.
- If the former, then something is really wrong the runtime.
- */
- SHLDebugStr("\pException reached ShellMain. Possibly ODInitExceptions failed");
- ENDTRY
-
- return 0;
- }
-
- #ifdef __cplusplus
- }
- #endif
-
- #pragma lib_export off
-
- //==============================================================================
- // Static Functions
- //==============================================================================
-
- #if ODDebug
- static ODBoolean isThisKeyDown(ODUShort theKey) // generic function
- {
- unsigned char theKeys[16];
- GetKeys((UInt32*)&theKeys);
-
- return ((theKeys[theKey >> 3] >> (theKey & 7)) & 1);
- }
- static ODBoolean isHeapKeyDown() // use 'h' to mean "heap"
- {
- const ODUShort heapKey = 4; // the 'h' key
- return isThisKeyDown(heapKey);
- }
- static ODBoolean isFilterKeyDown() // use 'f' to mean "filter"
- {
- const ODUShort filterKey = 3; // the 'f' key
- return isThisKeyDown(filterKey);
- }
- #endif
-
- static ODBoolean isOptionKeyDown()
- {
- const ODUShort theKey = 0x3A; // option key
- unsigned char theKeys[16];
- GetKeys((UInt32*)&theKeys);
-
- return ((theKeys[theKey >> 3] >> (theKey & 7)) & 1);
- }
-
- #if ODDebug
-
- static void
- ParamTextHeapInfo( )
- {
- const char *name;
- size_t allocated, free,blocks,objects,contig;
-
- MMGetHeapInfo(kDefaultHeapID,
- &name, &allocated, &free, &blocks, &objects);
- char nameStr[256], infoStr[256], appInfoStr[256];
- strcpy((char*)nameStr, name);
- sprintf(infoStr,"%lu\r%lu (%.1f%%)\r%lu (%lu objs)",
- allocated, free,
- 100.0*free/(float)(allocated+free),
- blocks,objects);
-
- MMSystemFreeSpace(kMMAppMemory, &free,&contig);
- allocated = (ApplicationZone()->bkLim-(Ptr)&ApplicationZone()->heapData) - free;
- sprintf(appInfoStr,"%lu\r%lu (%.1f%%)\r%lu",
- allocated, free,
- 100.0*free/(float)(allocated+free),
- contig);
-
- ParamText(CToPascalString(nameStr),CToPascalString(infoStr),
- "\pMacOS Application Heap",CToPascalString(appInfoStr));
- }
-
- static void HeapInfo()
- {
- ParamTextHeapInfo();
- ODSLong savedRefNum;
- BeginUsingLibraryResources(savedRefNum);
- NoteAlert(kODHeapInfoAlert, NULL);
- EndUsingLibraryResources(savedRefNum);
- }
-
- #endif
-
-
- //==============================================================================
- // RealShell
- //==============================================================================
-
-
- //-------------------------------------------------------------------------------------
- // Initialization
- //-------------------------------------------------------------------------------------
-
- RealShell::RealShell()
- {
- fEV = kODNULL;
- fSession = kODNULL;
- fDispatcher = kODNULL;
- fWindowState = kODNULL;
- fSIHelper = kODNULL;
-
- fAlreadyInCoercion = kODFalse;
- fErrorFromOpenEvents = noErr;
- fUniqueNameSeed = 1;
- fShellHasMenuFocus = kODFalse;
- fLastNewDocPSN.lowLongOfPSN = kNoProcess;
-
- fSaveCopyData = kODNULL;
- fSaveDiffVolDialog = kODNULL;
-
- fLowMemNotified = kODFalse;
-
- fFailedPlugInName[0] = 0;
- }
-
-
- RealShell::~RealShell()
- {
-
- ODDeleteObject(fSIHelper);
-
- this->ExportClipboard(kODFalse);
- #ifdef SHLHeapDebug
- SHLDebugStr("\pPostCloseDoc/PreSessionDelete HeapInfo…");
- HeapInfo();
- #endif
- delete fSession;
- #ifdef SHLHeapDebug
- SHLDebugStr("\pPostSessionDelete HeapInfo…");
- HeapInfo();
- #endif
-
- #if ODDebug
- if( gDumpBlocksOnClose ) {
- somPrintf("SOM objects and tracked blocks in heap contents after closing the session:\n");
- DumpHeapObjects(/*objectsOnly*/ kODFalse);
- }
- #endif
- WASSERT(fSaveDiffVolDialog==kODNULL);
- }
-
-
-
- void RealShell::Initialize()
- {
- fEV = somGetGlobalEnvironment();
-
- fSession = new ODSession;
- THROW_IF_NULL(fSession); // som objects don't autothrow if unable to allocate.
- fSession->InitSession(fEV);
- // Note: we need fDispatcher & fWindowState BEFORE ShellPlugIns are installed.
- fDispatcher = fSession->GetDispatcher(fEV);
- fWindowState = fSession->GetWindowState(fEV);
-
- // Is the app curently the active process?
- ProcessSerialNumber me = {0,kCurrentProcess};
- ProcessSerialNumber cur;
- GetFrontProcess(&cur);
- SameProcess(&me,&cur,&fProcessIsActive);
-
- this->InstallMenuBar();
- this->InitAE();
- this->InitMemory();
- }
-
- void RealShell::InstallMenuBar()
- {
- ODSLong savedRefNum;
- BeginUsingLibraryResources(savedRefNum);
-
- ODPlatformMenuBar menuBar;
- menuBar = GetNewMBar(kODAppleMenuID);
-
- if( !menuBar ) THROW(resNotFound);
- SetMenuBar(menuBar);
-
- MenuHandle appleMenu = GetMenuHandle(kODAppleMenuID);
- DetachResource((Handle)appleMenu);
-
- #if ODDebugMenu
- // Add "ODDebug" menu item, with submenu, below "About..." command:
- InsertMenuItem(appleMenu,"\pODDebug",1);
- SetItemCmd(appleMenu,2,0x1B);
- SetItemMark(appleMenu,2, kDebugMenuID);
-
- MenuHandle dbMenu = NewMenu(kDebugMenuID,"\pODDebug");
- THROW_IF_NULL(dbMenu);
- AppendMenu(dbMenu, "\pHeap Info;"
- "Memory Validation;"
- "Heap Checking;"
- "Leak Checking;"
- "Dump Blocks On Close;"
- "Track Block Stack Crawls;"
- "Eat Memory;"
- "Purge;"
- "(-;"
- "Log To stdout File;"
- "Log To DebugWindow;"
- "Generate DebugStrs;"
- "Dump ODObjects;"
- "Dump Tracked Blocks;"
- "(-;"
- "Break On THROW;"
- "SOM Trace" );
- InsertMenu(dbMenu,hierMenu);
-
- const int kNumDebugMenuItems = 17;
-
- static const ODCommandID kDBCommands[kNumDebugMenuItems] = {kODCommandDBHeapInfo,
- kODCommandDBMemValidation,
- kODCommandDBHeapChecking,
- kODCommandDBLeakChecking,
- kODCommandDBDumpBlocksOnClose,
- kODCommandDBTrackStackCrawls,
- kODCommandDBEatMemory,
- kODCommandDBPurge,
- /* Used below... */ 0,
- kODCommandDBLogStdout,
- kODCommandDBLogDebugWindow,
- kODCommandDBLogDebugStr,
- kODCommandDBDumpObjects,
- kODCommandDBDumpBlocks,
- 0,
- kODCommandDBBreakOnThrow,
- kODCommandDBSOMTrace};
-
- DisposeHandle((Handle)menuBar); // Update menuBar variable with new menu
- menuBar = GetMenuBar();
- #endif
-
- // create a new ODMenuBar object
- TempODMenuBar baseMenuBar = fWindowState->CreateMenuBar(fEV, menuBar);
-
- // add DA names to Apple menu
- AppendResMenu(appleMenu, kODDASMenuRsrc);
-
- MenuHandle documentMenu = GetMenu(kODDocumentMenuID);
-
- DetachResource((Handle)documentMenu);
- baseMenuBar->AddMenuLast(fEV, kODDocumentMenuID, documentMenu, kODNULL);
-
- MenuHandle editMenu = GetMenu(kODEditMenuID);
- DetachResource((Handle)editMenu);
- baseMenuBar->AddMenuLast(fEV, kODEditMenuID, editMenu, kODNULL);
-
- // Save off the default undo and redo menu items so that we can use them when
- // there's nothing on the undo or redo stack.
-
- this->SaveMenuItem(appleMenu, kSHLMenuAbout, &fDefaultAboutMenuItem);
- this->SaveMenuItem(editMenu, kSHLMenuUndo, &fDefaultUndoMenuItem);
- this->SaveMenuItem(editMenu, kSHLMenuRedo, &fDefaultRedoMenuItem);
- this->SaveMenuItem(editMenu, kSHLMenuPreferences, &fDefaultPrefsMenuItem);
-
- EndUsingLibraryResources(savedRefNum);
-
- baseMenuBar->RegisterCommand(fEV, kODCommandAppleMenu, kODAppleMenuID, 0);
- baseMenuBar->RegisterCommand(fEV, kODCommandAbout, kODAppleMenuID, kSHLMenuAbout);
-
- baseMenuBar->RegisterCommand(fEV, kODCommandDocumentMenu, kODDocumentMenuID, 0);
- baseMenuBar->RegisterCommand(fEV, kODCommandNew, kODDocumentMenuID, kSHLMenuNew);
- baseMenuBar->RegisterCommand(fEV, kODCommandOpen, kODDocumentMenuID, kSHLMenuOpen);
- baseMenuBar->RegisterCommand(fEV, kODCommandOpenDocument, kODDocumentMenuID, kSHLMenuOpenDocument);
- baseMenuBar->RegisterCommand(fEV, kODCommandInsert, kODDocumentMenuID, kSHLMenuInsert);
- baseMenuBar->RegisterCommand(fEV, kODCommandClose, kODDocumentMenuID, kSHLMenuClose);
- baseMenuBar->RegisterCommand(fEV, kODCommandDeleteDocument, kODDocumentMenuID, kSHLMenuDeleteDocument);
-
- baseMenuBar->RegisterCommand(fEV, kODCommandSave, kODDocumentMenuID, kSHLMenuSave);
- baseMenuBar->RegisterCommand(fEV, kODCommandSaveACopy, kODDocumentMenuID, kSHLMenuSaveACopy);
- baseMenuBar->RegisterCommand(fEV, kODCommandRevert, kODDocumentMenuID, kSHLMenuRevert);
- baseMenuBar->RegisterCommand(fEV, kODCommandDraft, kODDocumentMenuID, kSHLMenuDraft);
- baseMenuBar->RegisterCommand(fEV, kODCommandDocumentInfo, kODDocumentMenuID, kSHLMenuDocumentInfo);
-
- baseMenuBar->RegisterCommand(fEV, kODCommandPageSetup, kODDocumentMenuID,
- kSHLMenuPageSetup );
- baseMenuBar->RegisterCommand(fEV, kODCommandPrint, kODDocumentMenuID,
- kSHLMenuPrint );
-
- baseMenuBar->RegisterCommand(fEV, kODCommandEditMenu, kODEditMenuID, 0);
- baseMenuBar->RegisterCommand(fEV, kODCommandUndo, kODEditMenuID, kSHLMenuUndo);
- baseMenuBar->RegisterCommand(fEV, kODCommandRedo, kODEditMenuID, kSHLMenuRedo);
- baseMenuBar->RegisterCommand(fEV, kODCommandCut, kODEditMenuID, kSHLMenuCut);
- baseMenuBar->RegisterCommand(fEV, kODCommandCopy, kODEditMenuID, kSHLMenuCopy);
- baseMenuBar->RegisterCommand(fEV, kODCommandPaste, kODEditMenuID, kSHLMenuPaste);
- baseMenuBar->RegisterCommand(fEV, kODCommandPasteAs, kODEditMenuID, kSHLMenuPasteAs);
- baseMenuBar->RegisterCommand(fEV, kODCommandClear, kODEditMenuID, kSHLMenuClear);
- baseMenuBar->RegisterCommand(fEV, kODCommandSelectAll, kODEditMenuID, kSHLMenuSelectAll);
- baseMenuBar->RegisterCommand(fEV, kODCommandGetPartInfo, kODEditMenuID, kSHLMenuGetPartInfo);
- baseMenuBar->RegisterCommand(fEV, kODCommandPreferences, kODEditMenuID, kSHLMenuPreferences);
- baseMenuBar->RegisterCommand(fEV, kODCommandViewAsWin, kODEditMenuID, kSHLMenuViewAsWin);
-
- #if ODDebugMenu
- for( short i=0; i<kNumDebugMenuItems; i++ )
- if( kDBCommands[i] )
- baseMenuBar->RegisterCommand(fEV, kDBCommands[i], kDebugMenuID, i+1);
- #endif
-
- fWindowState->SetBaseMenuBar(fEV,baseMenuBar);
- baseMenuBar->Display(fEV);
- }
-
- //------------------------------------------------------------------------------
- // RealShell::SaveMenuItem
- //------------------------------------------------------------------------------
-
- void RealShell::SaveMenuItem(MenuHandle menu, short itemNum, MenuItemInfo* info)
- {
- GetMenuItemText(menu, itemNum, (*info).text);
- GetItemCmd(menu, itemNum, &(*info).cmdChar);
- GetItemIcon(menu, itemNum, &(*info).iconID);
- GetItemMark(menu, itemNum, &(*info).markChar);
- GetItemStyle(menu, itemNum, &(*info).textStyle);
- }
-
- //------------------------------------------------------------------------------
- // RealShell::RestoreMenuItem
- //------------------------------------------------------------------------------
-
- void RealShell::RestoreMenuItem(MenuHandle menu, short itemNum, MenuItemInfo* info)
- {
- SetMenuItemText(menu, itemNum, (*info).text);
- SetItemCmd(menu, itemNum, (*info).cmdChar);
- SetItemIcon(menu, itemNum, (*info).iconID);
- SetItemMark(menu, itemNum, (*info).markChar);
- SetItemStyle(menu, itemNum, (*info).textStyle);
- }
-
- //------------------------------------------------------------------------------
- // RealShell::InstallShellPlugIns
- //------------------------------------------------------------------------------
-
- void RealShell::InstallShellPlugIns(ODDraft* draft)
- {
- // get reference to OpenDoc Shell PlugIns directory
- ODSShort fldrVRefNum=0;
- ODSLong fldrDirID=0;
-
- TRY{
- FindShellPlugInsFolder(&fldrVRefNum, &fldrDirID);
- this->ScanShellPlugInsFldr(fldrVRefNum, fldrDirID, draft);
- }CATCH_ALL{
- if ( fFailedPlugInName[0] )
- RERAISE;
- }ENDTRY
-
- }
-
- //------------------------------------------------------------------------------
- // GetCfrgInfo
- // Given a file spec, find the record within the 'cfrg' resource in that
- // file that corresponds to the platform we're on and the symbol we're
- // looking for. Having found it, return the offset and length from the
- // record; failing, return an error.
- //------------------------------------------------------------------------------
-
- ODStatic OSErr GetCfrgInfo( ODFileSpec* fileSpec, long* offset, long* length )
- {
- struct FragDesc {
- ResType codeType;
- long ignore[5];
- long offsetToFrag;
- long lengthOfFrag;
- long moreIgnore[2];
- short recordLength;
- Str63 name;
- };
-
- struct CFRGResource {
- long ignore[7];
- long numFrags;
- struct FragDesc firstDesc;
- };
-
- OSErr err = resNotFound;
-
- short refNum = HOpenResFile( fileSpec->vRefNum, fileSpec->parID,
- fileSpec->name, fsRdPerm );
- short saveRefNum = CurResFile();
- UseResFile( refNum );
-
- struct CFRGResource** cfrgHandle =
- (struct CFRGResource**)Get1Resource( 'cfrg', 0 );
- if ( cfrgHandle )
- {
- long entryCount = (*cfrgHandle)->numFrags;
- #ifdef ODDebug
- if ( entryCount > 2 )
- WARN( "Plugin cfrg has more than 2 entries (ie isn't just fat)"
- " and we aren't checking names" );
- #endif
- struct FragDesc* oneEntryPtr = &(*cfrgHandle)->firstDesc;
- while ( entryCount-- )
- {
- if ( oneEntryPtr->codeType == kCurrentCFragArch )
- {
- *offset = oneEntryPtr->offsetToFrag;
- *length = oneEntryPtr->lengthOfFrag;
- err = noErr;
- break;
- }
- else
- oneEntryPtr = (FragDesc*)(oneEntryPtr->recordLength
- + (char*)oneEntryPtr);
- }
- }
- else
- err = ResError();
-
- CloseResFile( refNum );
- UseResFile( saveRefNum );
- return err;
- }
-
- //------------------------------------------------------------------------------
- // RealShell::ScanShellPlugInsFldr
- //------------------------------------------------------------------------------
-
- void RealShell::ScanShellPlugInsFldr(ODSShort fldrVRefNum, ODSLong fldrDirID,
- ODDraft* draft)
- {
- // iterate through files in that directory (code copied from Prefs.cpp:LoadNameSpaceTable)
- ODFileSpec theFileSpec;
- CInfoPBRec CinfoPB;
- Str255 fileName;
-
- memset (&CinfoPB,0,sizeof(CinfoPB));
- CinfoPB.hFileInfo.ioNamePtr = (StringPtr)fileName;
- CinfoPB.hFileInfo.ioFDirIndex = 1;
- CinfoPB.hFileInfo.ioVRefNum = fldrVRefNum;
- CinfoPB.hFileInfo.ioDirID = fldrDirID;
-
- TempPlatformFile file(new PlatformFile);
-
- for( ODSShort i = PBGetCatInfoSync( &CinfoPB );
- i == noErr;
- i = PBGetCatInfoSync( &CinfoPB ) )
- {
- // if this is not a folder and we successfully create an FSSpec
- if (( ! (CinfoPB.hFileInfo.ioFlAttrib & (1<<4)) )
- && ( noErr == (FSMakeFSSpec( CinfoPB.hFileInfo.ioVRefNum,
- CinfoPB.hFileInfo.ioFlParID, //ioDirID,
- fileName,
- &theFileSpec ) ) ))
- {
- file->Specify(&theFileSpec);
- if ( file->GetPlatformType() == kCFragLibraryFileType)
- {
- CFragConnectionID connID;
- Ptr mainAddr;
- Str255 errName;
-
- long length;
- long offset;
- OSErr err = GetCfrgInfo( &theFileSpec, &offset, &length );
-
- if ( !err )
- err = GetDiskFragment( &theFileSpec, offset, length,
- NULL, kNewCFragCopy, &connID, &mainAddr,
- errName );
- if ( !err )
- {
- ODShellPlugInInstallProc installMethod;
- CFragSymbolClass symClass;
- err = FindSymbol( connID, "\pODShellPlugInInstall",
- (Ptr*)&installMethod, &symClass );
- ODShellPlugInActionCodes action
- = kODShellPlugInNoAction;
- if ( !err )
- {
- WASSERT( symClass == kTVectorCFragSymbol );
- TRY
- err = (*installMethod)( fEV, draft, &action );
- SetErrorCode(kODNoError);
- CATCH_ALL
- SetErrorCode(kODNoError);
- ENDTRY
- }
- // else is not a shell plugin; continue with next file
-
- // test again; if the FindSymbol call failed we
- // still want to close the connection
- if ( (err != noErr) ||
- BITTEST(action, kODShellPlugInCloseConnection) )
- err = CloseConnection( &connID );
- }
- if ( err )
- {
- ODBlockMove( theFileSpec.name, fFailedPlugInName,
- theFileSpec.name[0]+1 );
- THROW( err );
- }
- }
- }
- CinfoPB.hFileInfo.ioFDirIndex++;
-
- //need to do this each time since PBGetCatInfo call returns val here
- CinfoPB.hFileInfo.ioNamePtr = (StringPtr)fileName;
- CinfoPB.hFileInfo.ioVRefNum = fldrVRefNum;
- CinfoPB.hFileInfo.ioDirID = fldrDirID;
- }
- }
-
- //------------------------------------------------------------------------------
- // FindShellPlugInsFolder //ccg
- //------------------------------------------------------------------------------
-
- static void FindShellPlugInsFolder(short *vol, long *dir )
- {
- Str255 folderName;
-
- CInfoPBRec pb;
- memset (&pb,0,sizeof(pb));
-
- //First find System Folder
- THROW_IF_ERROR( FindFolder(kOnSystemDisk, kSystemFolderType, kDontCreateFolder,
- &pb.dirInfo.ioVRefNum, &pb.dirInfo.ioDrDirID) );
-
- // find Shell Plug Ins Folder path name
- ODGetString(folderName, kODEditorsFldrStrID);
- pb.dirInfo.ioNamePtr = (StringPtr)&folderName;
- pb.dirInfo.ioFDirIndex = 0;
- THROW_IF_ERROR( PBGetCatInfoSync( &pb ) );
-
- ODGetString(folderName, kODOpenDocPartsFolderStrID);
- pb.dirInfo.ioNamePtr = (StringPtr)&folderName;
- pb.dirInfo.ioFDirIndex = 0;
- THROW_IF_ERROR( PBGetCatInfoSync( &pb ) );
-
- ODGetString(folderName, kODShellPlugInFolderStrID);
- pb.dirInfo.ioNamePtr = (StringPtr)&folderName;
- pb.dirInfo.ioFDirIndex = 0;
- THROW_IF_ERROR( PBGetCatInfoSync( &pb ) );
-
- *vol = pb.dirInfo.ioVRefNum;
- *dir = pb.dirInfo.ioDrDirID;
- }
- //------------------------------------------------------------------------------
- // FindStationeryFolder
- //------------------------------------------------------------------------------
- static void FindStationeryFolder(short *vol, long *dir )
- {
- Str255 folderName;
- ODSLong unused;
-
- CInfoPBRec pb;
- memset (&pb,0,sizeof(pb));
-
- //First find Desktop Folder
- THROW_IF_ERROR( FindFolder(kOnSystemDisk, kDesktopFolderType, kCreateFolder,
- vol, &unused ));
-
- // find Stationery Folder path name
- ODGetString(folderName, kODStationeryFldrStrID);
- pb.dirInfo.ioNamePtr = (StringPtr)&folderName;
- pb.dirInfo.ioDrDirID = fsRtDirID; //2;
- pb.dirInfo.ioVRefNum = *vol;
- pb.dirInfo.ioFDirIndex = 0;
- if ( PBGetCatInfoSync( &pb ) )
- {
- THROW_IF_ERROR(
- DirCreate(*vol, fsRtDirID, folderName, dir));
- } else {
- *dir = pb.dirInfo.ioDrDirID;
- }
- }
-
- //-------------------------------------------------------------------------------------
- // RealShell::go
- //-------------------------------------------------------------------------------------
-
- void RealShell::go()
- {
- ODBoolean initialized;
- ODVolatile(initialized);
- ODULong errorLoops = 0; // Counts the number of times in a row we caught
- // an out-of-memory error in the event loop.
- ODVolatile(errorLoops);
-
- #if ODDebug
- if ( gDumpBlocksOnClose )
- {
- SetOutputMode(kWriteToFile);
- // MMBeginLeakChecking();
- // gLeakChecking = kODTrue;
- MMTrackStackCrawls( kODTrue );
- }
- #endif
-
- {
- TRY
- this->Initialize();
- initialized = kODTrue;
- CATCH_ALL
- initialized = kODFalse;
- this->ExceptionAlert(ErrorCode(),ErrorMessage());
- ENDTRY
- }
-
- #ifdef SHLTestErrorDialogUsage
- SHLDebugStr("\pPreErrorDialog HeapInfo…");
- HeapInfo();
- this->ExceptionAlert(1,kODNULL);
- #endif
-
- #ifdef SHLTestSessionOverhead
- SHLDebugStr("\pPreExtraSession HeapInfo…");
- HeapInfo();
-
- TRY
- TempODSession aSession = new ODSession;
- THROW_IF_NULL(aSession); // som objects don't autothrow if unable to allocate.
- aSession->InitSession(fEV);
- CATCH_ALL
- ENDTRY
-
- SHLDebugStr("\pPostExtraSession HeapInfo…");
- HeapInfo();
- #endif
-
- EventRecord eventRec;
- if (initialized)
- while (!fDispatcher->ShouldExit(fEV))
- {
- TRY
- if ( gODBentoFatalErrorHasOccurred )
- ODBentoFatalError();
-
- if( this->CheckFileLocation() ) // Update if document renamed/moved
- break; // we may need to quit if trashed
-
- ODSLong sleep = fDispatcher->GetSleepTime(fEV);
- if( sleep > kMaxTimeBetweenLocationChecks )
- sleep = kMaxTimeBetweenLocationChecks;
-
- WaitNextEvent (everyEvent, &eventRec, sleep, fDispatcher->GetMouseRegion(fEV));
- if( eventRec.what == osEvt && (( eventRec.message >> 24 ) & 0x00FF)==0x01 )
- fProcessIsActive= (eventRec.message & 0x01)!=0;
-
- this->DispatchEvent((ODEventData*)&eventRec);
-
- this->CheckMenuBar();
-
- if( fProcessIsActive )
- this->CheckFreeMemory(); // Display low-mem alert
-
- errorLoops = 0; // Reset this. We got through the loop OK.
-
- CATCH_ALL
-
- // IF WE CATCH A LOW-MEMORY ERROR HERE MORE THAN 2 TIMES IN A ROW,
- // WE OUTTIE.
- ODError thisError = ErrorCode();
- if (thisError == kODErrOutOfMemory || thisError == memFullErr)
- {
- ++errorLoops;
- if (errorLoops > 2)
- ODShellLowMemoryGoodbye();
- }
-
- this->ExceptionAlert(ErrorCode(),ErrorMessage());
-
- ENDTRY
-
- }
-
- // Check to see if we failed in the odoc or oapp appleevent handlers.
- ODError err = this->GetAEError();
- if (err)
- {
- this->ExceptionAlert(err,kODNULL);
- }
- }
-
-
- //-------------------------------------------------------------------------------------
- // Notification Stuff
- //-------------------------------------------------------------------------------------
-
- struct NotEntry :public Link {
- RealShell::Notifier n;
- ODULong refCon;
- NMRec nm;
-
- virtual ~NotEntry( );
- };
-
- NotEntry::~NotEntry( )
- {
- if( nm.nmIcon ) DisposeIconSuite(nm.nmIcon,kODTrue);
- }
-
- static ODIconFamily
- GetRootPartIconFamily( Environment* ev, ODSession* session )
- {
- static ODIconFamily sIcon = kODNULL;
- if( !sIcon ) {
- TempODWindow odWindow = session->GetWindowState(ev)->AcquireFrontRootWindow(ev);
- ODFrame* rootFrame = odWindow ? odWindow->GetRootFrame(ev) : kODNULL;
- sIcon = ODGetIconFamily(ev, rootFrame);
- }
- return sIcon;
- }
-
-
- //-------------------------------------------------------------------------------------
- // RealShell::Notify
- //-------------------------------------------------------------------------------------
-
- void
- RealShell::Notify( RealShell::Notifier n, ODULong refCon )
- {
- if( fProcessIsActive )
- (this->*n)( refCon ); // We're active, so call notifier right now.
-
- else {
- NotEntry *e = new NotEntry;
- e->n = n;
- e->refCon = refCon;
- fNotifiers.AddLast(e);
-
- e->nm.qType = nmType;
- e->nm.nmMark = 1; // Mark process menu
- e->nm.nmIcon = GetRootPartIconFamily(fEV, fSession); // Show root part's icon
- e->nm.nmSound = (Handle)-1L; // Play system beep
- e->nm.nmStr = kODNULL;
- e->nm.nmResp = kODNULL;
- OSErr err= NMInstall(&e->nm);
- WASSERT(err==noErr);
- }
- }
-
-
- //-------------------------------------------------------------------------------------
- // RealShell::CancelNotification
- //-------------------------------------------------------------------------------------
-
- void
- RealShell::CancelNotification( RealShell::Notifier n )
- {
- // Removes all notifications pointing to this notifier proc.
- NotEntry *next;
- for( NotEntry *e = (NotEntry*)fNotifiers.First(); e; e=next ) {
- next = (NotEntry*)fNotifiers.After(*e);
- if( e->n == n ) {
- NMRemove(&e->nm);
- fNotifiers.Remove(*e);
- delete e;
- }
- }
- }
-
-
- //-------------------------------------------------------------------------------------
- // RealShell::ShowPendingNotification
- //-------------------------------------------------------------------------------------
-
- void
- RealShell::ShowPendingNotifications( )
- {
- if( fProcessIsActive ) {
- NotEntry *e;
- while( !fNotifiers.IsEmpty() ) {
- e = (NotEntry*) fNotifiers.RemoveFirst();
- NMRemove(&e->nm);
- (this->*(e->n))( e->refCon ); // Call notifier method
- delete e;
- }
- }
- }
-
-
- //-------------------------------------------------------------------------------------
- // RealShell::DispatchEvent
- //-------------------------------------------------------------------------------------
-
- void RealShell::DispatchEvent(ODEventData* event)
- {
- switch (event->what)
- {
- case kODEvtMouseDown:
- this->DispatchMouseDownEvent(event);
- break;
-
- case kODEvtKeyDown:
- this->DispatchKeyDownEvent(event);
- break;
-
- case kODEvtOS:
- // FOR NOW, EAT ALL ERRORS OCCURING DURING A SUSPEND.
- // SEE WHAT TYPE OF OS EVENT IT IS
- ODUByte typeOSEvent = (ODUByte) (event->message >> 24) & 0x00FF;
- ODBoolean isSuspendEvent;
-
- // IF IT'S A SUSPEND MESSAGE
- isSuspendEvent = ((typeOSEvent & suspendResumeMessage)
- && (!(event->message & resumeFlag)));
- TRY
- fDispatcher->Dispatch(fEV,event);
- this->HandleOSEvent(event);
- CATCH_ALL
- if (isSuspendEvent)
- WARN("Eating an error that occurred during suspend time.");
- else
- RERAISE;
- ENDTRY
- break;
-
- case kHighLevelEvent:
- if (!fDispatcher->Dispatch(fEV,event))
- this->HandleHighLevelEvent(event);
- break;
-
- default:
- fDispatcher->Dispatch(fEV,event);
- break;
- }
- }
-
- //-------------------------------------------------------------------------------------
- // RealShell::DispatchMouseDownEvent
- //-------------------------------------------------------------------------------------
-
- void RealShell::DispatchMouseDownEvent(ODEventData* event)
- {
- WindowPtr theWindow = kODNULL;
- ODSShort partCode = FindWindow(event->where, &theWindow);
- if (partCode == kODMDInMenuBar)
- this->DispatchMenuEvent(event);
- else if (!(fDispatcher->Dispatch(fEV,event)) && theWindow)
- this->HandleMouseDownInWindow(theWindow, partCode, event);
- }
-
- //-------------------------------------------------------------------------------------
- // RealShell::DispatchMenuEvent
- //-------------------------------------------------------------------------------------
-
- void RealShell::DispatchMenuEvent(ODEventData* event)
- {
- this->UpdateMenus();
- if (!(fDispatcher->Dispatch(fEV,event)))
- this->HandleMenuCommand(event->message, event);
- }
-
- //-------------------------------------------------------------------------------------
- // RealShell::DispatchKeyDownEvent
- //-------------------------------------------------------------------------------------
-
- void RealShell::DispatchKeyDownEvent(ODEventData* event)
- {
- ODBoolean cmdKeyDown = (event->modifiers & cmdKey) != 0;
- ODBoolean optionKeyDown = (event->modifiers & optionKey) != 0;
- if (cmdKeyDown) // || F1, f2, f3, f4 were pressed
- this->UpdateMenus();
- // Fix #1221897
- // should also do update if function keys for Undo/Cut/Copy/Paste were pressed
-
- if ( !fDispatcher->Dispatch(fEV, event) )
- {
- if ( event->what == kODEvtMenu )
- this->HandleMenuCommand(event->message, event );
- else if ( cmdKeyDown && optionKeyDown )
- {
- // we have a command-key equivalent that didn't get recognized
- // because UI doesn't like the option key. So we need to change
- // the character to what it would be without the option, then get
- // the equivalent menu and invoke its handler with the additional
- // information that the option key was down.
-
- // Adapted from Finder code furnished by Greg Anderson
- unsigned char key = event->message & charCodeMask;
- short mangledKeyCode = (short)((event->message & keyCodeMask) >> 8)
- | (event->modifiers & keyCodeMask); // raw key w/ all modifiers
- UInt32 state = 0;
- Ptr kchrCache = (Ptr)GetScriptManagerVariable(smKCHRCache);
-
- // Find out if the raw key code matches the character in event.message.
- unsigned char computedKey = // only keep low byte
- (unsigned char)KeyTranslate( kchrCache, mangledKeyCode,
- &state );
-
- if (computedKey == key)
- {
- mangledKeyCode &= (0xFFFF - optionKey); // mask out option bit
- key = (unsigned char) KeyTranslate(kchrCache, mangledKeyCode, &state);
- // only keep low byte; we'll use this new keycode w/o option.
-
- // NOTE: I'm not changing the event, which HandleMenuCommand
- // ignores anyway.
- // ODBoolean oldOptionValue = fOptionKeyDownOnMenuBarClick;
- fOptionKeyDownOnMenuBarClick = kODTrue;
- this->HandleMenuCommand( MenuKey(key), event );
- // fOptionKeyDownOnMenuBarClick = oldOptionValue;
- }
- }
- }
- }
-
- //-------------------------------------------------------------------------------------
- // RealShell::HandleOSEvent
- //-------------------------------------------------------------------------------------
-
- void RealShell::HandleOSEvent(ODEventData* event)
- {
- // Is it a multifinder event?
- ODUByte typeOSEvent = (ODUByte) (event->message >> 24) & 0x00FF;
-
- // Switch on the type of OSEvent that occurred, high byte of message is event type
- switch (typeOSEvent)
- {
- case suspendResumeMessage:
- if( event->message & resumeFlag )
- this->ShowPendingNotifications(); // Display pending notifications
- else
- this->ExportClipboard(kODFalse);
- break;
- }
- }
-
- //-------------------------------------------------------------------------------------
- // RealShell::ExportClipboard
- //-------------------------------------------------------------------------------------
-
- void RealShell::ExportClipboard(ODBoolean canAlert)
- {
- ODClipboard* clipboard = fSession->GetClipboard(fEV);
-
- // TRY
- clipboard->ExportClipboard(fEV);
- // CATCH_ALL
- // if ( canAlert )
- // this->ExceptionAlert(ErrorCode(),ErrorMessage());
- // ENDTRY;
- }
-
- //-------------------------------------------------------------------------------------
- // Debug Menu Support
- //-------------------------------------------------------------------------------------
-
-
- #if ODDebugMenu
-
- #define OBJECTMASTERKLUDGE
- #ifdef OBJECTMASTERKLUDGE
- extern "C" {
- #endif
-
- #define kDumpTmpBufSize 3000
-
- static char gFilterNewClass;
- // gFilterNewClass is a global with a unique address passed to DumpObjProc as refCon
-
- static MMBoolean DumpObjProc( const void *blk, size_t size, MMBoolean isObject,
- void *refCon )
- {
- if( isObject ) {
- MMValidateObject((ODObject*)blk);
- somPrintf(" %p %4lu %s\r", blk,size, ((ODObject*)blk)->somGetClassName());
- }
- return true; // Might check for cmd-period or something to abort...
- }
-
- static void DumpBlockStackCrawl( const void *blk, size_t size, ODBoolean isObject,
- ODBoolean filter )
- {
- long flags = 0;
- StackCrawl* sc = MMGetBlockStackCrawl( blk, &flags );
- if (sc)
- {
- if ( !isObject )
- {
- somPrintf("%p %4lu:\r", blk, size);
- }
- static const char* kTooLongString = "... [too long]\n";
- char buffer[kDumpTmpBufSize + 32]; // add 32 for kTooLongString
- buffer[0] = 0;
- long numFrames = sc->CountFrames();
- long pos = 0;
- for (long i = 0; i < numFrames && pos < kDumpTmpBufSize; i++)
- {
- size_t offset;
- char tmpBuffer[256];
- char fnName[256];
- if (sc->LookupSymbol(i, fnName, &offset))
- {
- sprintf(tmpBuffer, "%s+%d\n", fnName, offset);
- long newPos = pos + strlen(tmpBuffer);
- if ( newPos < kDumpTmpBufSize )
- sprintf(&(buffer[pos]), "%s", tmpBuffer);
- else
- strcpy(&(buffer[pos]), kTooLongString);
-
- pos = newPos;
- }
- }
- if ( filter )
- {
- if ( buffer[0] && !strstr(buffer, "NewClass") )
- somPrintf("%s\r", buffer);
- }
- else
- {
- if ( buffer[0] )
- somPrintf("%s\r", buffer);
- }
- }
- }
-
- #ifdef OBJECTMASTERKLUDGE
- }
- #endif
-
-
- struct TrackedBlockLink {
- TrackedBlockLink* fNext;
- const void* fFirstBlock;
- StackCrawl* fStack;
- unsigned long fCount;
- unsigned long fTotalSize;
- };
-
- static TrackedBlockLink* sTrackedBlockLinks;
-
- extern "C" {
- static MMBoolean
- FindObjsProc( const void *blk, size_t size, MMBoolean isObject, void *refCon )
- {
- long flags;
- StackCrawl* s = MMGetBlockStackCrawl(blk, &flags);
- if( s ) {
- size_t blockSize = MMBlockSize(blk);
-
- // This is a new block, check its stack crawl:
- TrackedBlockLink *l;
- for( l = sTrackedBlockLinks; l; l = l->fNext )
- if( *(l->fStack) == *s ) {
- l->fCount++;
- l->fTotalSize += blockSize;
- // delete s;
- // MMSetBlockStackCrawl(blk,kODNULL,0);
- return kODTrue;
- }
- l = new TrackedBlockLink;
- l->fNext = sTrackedBlockLinks;
- l->fFirstBlock = blk;
- l->fTotalSize = blockSize;
- l->fStack = s;
- l->fCount = 1;
- sTrackedBlockLinks = l;
- }
- return kODTrue;
- }
- }
-
- static void
- DumpFoundObjs()
- {
- unsigned long count = 0;
- unsigned long space = 0;
- TrackedBlockLink* next;
- ODBoolean filter = isFilterKeyDown();
-
- for( TrackedBlockLink * l = sTrackedBlockLinks; l; l = next ) {
- count += l->fCount;
- next = l->fNext;
- // if( l->fCount >= 3 ) {
- somPrintf("• Occurred %lu time%s, %lu total bytes:\r",
- l->fCount, (l->fCount == 1)? "": "s", l->fTotalSize);
- size_t size = MMBlockSize(l->fFirstBlock);
- ODBoolean isObject = MMIsObject(l->fFirstBlock);
-
- DumpObjProc(l->fFirstBlock, size, isObject, kODNULL);
- DumpBlockStackCrawl(l->fFirstBlock, size, isObject, filter);
-
- space += l->fTotalSize + (l->fCount * 8); // Add 8 bytes for per-block overhead
- // }
- delete l;
- }
- sTrackedBlockLinks = kODNULL;
- if( space > 0 )
- somPrintf("••• Estimated space in %lu tracked blocks: %lu bytes\r", count, space);
- else
- somPrintf("••• No tracked blocks found!\r");
- }
-
- static void
- DumpHeapObjects( ODBoolean objectsOnly )
- {
- const char *name;
- size_t allocated, free,blocks,objects;
- MMGetHeapInfo(kDefaultHeapID,
- &name, &allocated, &free, &blocks, &objects);
- somPrintf("••• Dump of %s •••\r%lu bytes allocated, %lu free (%.1f%% free).\r",
- name, (ODULong)allocated, (ODULong)free, 100.0*free/(float)(allocated+free) );
- somPrintf("There are %lu blocks, of which %lu are objects:\r", (ODULong)blocks, (ODULong)objects);
-
- if ( !objectsOnly && gTrackStackCrawls )
- {
- sTrackedBlockLinks = kODNULL;
-
- MMTrackStackCrawls(kODFalse); // disable stack crawls in FindObjsProc()
- MMWalkHeap(kDefaultHeapID, &FindObjsProc, kODNULL);
- DumpFoundObjs();
- MMTrackStackCrawls(kODTrue); // re-enable stack crawls
-
- sTrackedBlockLinks = kODNULL;
- }
- else
- {
- somPrintf(" ADDRESS SIZE CLASS\r");
- MMWalkHeap(kDefaultHeapID, &DumpObjProc, kODNULL);
- }
- }
-
-
- #endif
-
- //-------------------------------------------------------------------------------------
- // RealShell::HandleMenuCommand
- //-------------------------------------------------------------------------------------
-
-
- void RealShell::HandleMenuCommand(ODSLong menuResult, ODEventData* event)
- {
- ODUnused(event);
-
- ODSShort menu = HiWord(menuResult);
- ODSShort item = LoWord(menuResult);
- TempODMenuBar menuBar = fWindowState->AcquireCurrentMenuBar(fEV);
- ODCommandID command = menuBar->GetCommand(fEV,menu, item);
-
- if (menuBar->IsCommandSynthetic(fEV,command))
- {
- switch (menu)
- {
- case kODAppleMenuID: // Apple
- {
- Str255 daName;
- ODSShort daRefNum;
-
- GetMenuItemText(GetMenuHandle(kODAppleMenuID), item, daName);
- daRefNum = OpenDeskAcc(daName);
- HiliteMenu(0);
- break;
- }
-
- default:
- break;
- }
- }
- else
- {
- ODDraft* activeDraft = ODGetActiveDraft(fEV, fSession);
- ODDocument* activeDocument;
- if (activeDraft)
- activeDocument = activeDraft->GetDocument(fEV);
- else
- activeDocument = kODNULL;
-
- switch(command)
- {
- case kODCommandAbout: {
- CUsingLibraryResources r;
- ODSShort itemHit;
- GrafPtr savePort;
- GetPort(&savePort);
-
- fWindowState->DeactivateFrontWindows(fEV);
- TRY
- DialogPtr aboutDlg = ShowAboutScreen();
-
- ModalDialog(kODNULL /*modalFilter*/, &itemHit);
- if (aboutDlg)
- DisposeDialog(aboutDlg);
- CATCH_ALL
- fWindowState->ActivateFrontWindows(fEV);
- RERAISE;
- ENDTRY
- fWindowState->ActivateFrontWindows(fEV);
-
- SetPort(savePort);
- break;
- }
-
- // POSSIBLE FIX NEEDED: needs to use activeDocument?
- case kODCommandNew: delete (this->New()); break;
-
- case kODCommandOpenDocument: this->OpenStdFile(); break;
-
- case kODCommandClose:
- if (fOptionKeyDownOnMenuBarClick)
- {
- this->CloseDocument(activeDocument, kAEAsk);
- }
- else
- {
- WindowPtr platformWindow = kODNULL;
- {
- TempODWindow window = ODAcquireActiveWindow(fEV, fSession);
- if (window)
- platformWindow = window->GetPlatformWindow(fEV);
- }
- this->CloseWindow(platformWindow, kAEAsk);
- }
- break;
-
- case kODCommandDeleteDocument: this->DeleteDocument(activeDocument); break;
-
- case kODCommandSave: this->Save(activeDocument); break;
-
- case kODCommandSaveACopy: this->SaveACopy(activeDraft); break;
-
- case kODCommandRevert: this->Revert(activeDocument); break;
-
- case kODCommandDraft: this->Drafts(activeDocument); break;
-
- case kODCommandDocumentInfo: this->DocumentInfo(activeDocument); break;
-
- case kODCommandUndo: fSession->GetUndo(fEV)->Undo(fEV); break;
-
- case kODCommandRedo: fSession->GetUndo(fEV)->Redo(fEV); break;
-
- // case kODCommandGetPartInfo: this->PartInfo(); break;
-
- #if ODDebugMenu
- case kODCommandDBHeapInfo: {
- HeapInfo();
- break;
- }
- case kODCommandDBDumpObjects:
- DumpHeapObjects( /*objectsOnly*/ kODTrue );
- break;
- case kODCommandDBDumpBlocks:
- DumpHeapObjects( /*objectsOnly*/ kODFalse );
- break;
- case kODCommandDBMemValidation:
- if( gMemValidation ) {
- if( gHeapChecking ) { // When turning off validation,
- MMEndHeapChecking(); // turn heap checking off too
- gHeapChecking = kODFalse;
- }
- MMEndMemValidation();
- gMemValidation = kODFalse;
- } else {
- MMBeginMemValidation();
- gMemValidation = kODTrue;
- }
- break;
- case kODCommandDBHeapChecking:
- if( gHeapChecking ) {
- MMEndHeapChecking();
- gHeapChecking = kODFalse;
- } else {
- MMBeginMemValidation(); // When turning on heap checking,
- gMemValidation = kODTrue; // turn validation on too
- MMBeginHeapChecking();
- gHeapChecking = kODTrue;
- }
- break;
- case kODCommandDBLeakChecking:
- if( gLeakChecking )
- MMEndLeakChecking();
- else
- MMBeginLeakChecking();
- gLeakChecking = !gLeakChecking;
- gTrackStackCrawls = gLeakChecking;
- break;
- case kODCommandDBDumpBlocksOnClose:
- gDumpBlocksOnClose = !gDumpBlocksOnClose;
- break;
- case kODCommandDBTrackStackCrawls:
- if( gTrackStackCrawls )
- MMTrackStackCrawls( kODFalse );
- else
- MMTrackStackCrawls( kODTrue );
- gTrackStackCrawls = !gTrackStackCrawls;
- break;
- case kODCommandDBEatMemory:
- (void) NewHandle(32*1024); // For testing low-mem survival!
- if( MemError() ) {
- SysBeep(3);
- WARN("Error %d eating memory!;ht",MemError());
- }
- break;
- case kODCommandDBPurge:
- this->Purge(10*1024*1024);
- break;
- case kODCommandDBLogStdout:
- if( GetOutputMode() != kWriteToFile )
- SetOutputMode(kWriteToFile);
- else
- SetOutputMode(kNoOutput);
- break;
- case kODCommandDBLogDebugWindow:
- if( GetOutputMode() != kWriteToDebugWindow )
- SetOutputMode(kWriteToDebugWindow);
- else
- SetOutputMode(kNoOutput);
- break;
- case kODCommandDBLogDebugStr:
- if( GetOutputMode() != kGenerateDebugStrs )
- SetOutputMode(kGenerateDebugStrs);
- else
- SetOutputMode(kNoOutput);
- break;
- case kODCommandDBBreakOnThrow:
- BreakOnThrow( ! BreakOnThrow(kODFalse) );
- // This looks weird, but we have to call it once to get the
- // old value, then again to set it to the opposite of that.
- break;
- case kODCommandDBSOMTrace:
- SOM_TraceLevel = !SOM_TraceLevel;
- break;
- #endif
-
- default:
- // some part enabled a menu command but did not handle it
- break;
- }
- HiliteMenu(0);
- }
- }
-
- //-------------------------------------------------------------------------------------
- // RealShell::HandleMouseDownInWindow
- //-------------------------------------------------------------------------------------
-
- void RealShell::HandleMouseDownInWindow(WindowPtr pwindow, ODSShort partCode, ODEventData* event)
- {
- switch (partCode)
- {
- case kODMDInGoAway:
- this->HandleMouseDownInCloseBox(pwindow, event);
- break;
-
- case kODMDInDrag:
- this->HandleMouseDownInDragRegion(pwindow, event);
- break;
-
- case kODMDInGrow:
- this->HandleMouseDownInGrowBox(pwindow, event);
- break;
-
- case kODMDInZoomIn:
- case kODMDInZoomOut:
- this->HandleMouseDownInZoomBox(pwindow, partCode,event);
- break;
-
- case kODMDInContent:
- {
- TempODWindow window = fWindowState->AcquireODWindow(fEV,pwindow);
- if (window != kODNULL)
- window->Select(fEV);
- else
- SelectWindow(pwindow);
- break;
- }
- default:
- break;
- }
- }
-
- //-------------------------------------------------------------------------------------
- // RealShell::HandleMouseDownInCloseBox
- //-------------------------------------------------------------------------------------
-
- void RealShell::HandleMouseDownInCloseBox(WindowPtr pwindow, ODEventData* event)
- {
- if (TrackGoAway (pwindow, event->where))
- {
- if (isOptionKeyDown())
- {
- ODDocument* document = kODNULL;
- {
- TempODWindow window = fWindowState->AcquireODWindow(fEV, pwindow);
- WASSERT(window != kODNULL);
- document = ODGetDraftOfWindow(fEV, window)->GetDocument(fEV);
- }
- this->CloseDocument(document, kAEAsk);
- }
- else
- this->CloseWindow(pwindow, kAEAsk);
- }
- }
-
- //-------------------------------------------------------------------------------------
- // RealShell::HandleMouseDownInDragRegion
- //-------------------------------------------------------------------------------------
-
- void RealShell::HandleMouseDownInDragRegion(WindowPtr platformWindow, ODEventData* event)
- {
- TempODWindow window = fWindowState->AcquireODWindow(fEV,platformWindow);
- if (window != kODNULL)
- {
- window->Drag(fEV, &event->where, (Rect*)&ODQDGlobals.screenBits.bounds);
- }
- else
- {
- WARN("Dragging non-ODWindow.");
- DragWindow(platformWindow, event->where, &(ODQDGlobals.screenBits.bounds));
- }
- }
-
- //-------------------------------------------------------------------------------------
- // RealShell::HandleMouseDownInGrowBox
- //-------------------------------------------------------------------------------------
-
- void RealShell::HandleMouseDownInGrowBox(WindowPtr pwindow, ODEventData* event)
- {
- if (!fWindowState->IsODWindow(fEV,pwindow))
- return;
-
- TempODWindow window = fWindowState->AcquireODWindow(fEV,pwindow);
-
- if (window == kODNULL)
- return;
-
- if (window->IsResizable(fEV))
- {
- Rect growLimits; // = ODQDGlobals.screenBits.bounds);
-
- ODRgnHandle contRgn =
- ((WindowRecord*)(window->GetPlatformWindow(fEV)))->contRgn;
- Rect currentBounds = (**contRgn).rgnBBox;
-
- window->GetWindowBounds(fEV, ¤tBounds);
-
- growLimits.left = currentBounds.right-currentBounds.left;
- if (growLimits.left > kMinWindowWidth)
- growLimits.left = kMinWindowWidth;
- growLimits.top = currentBounds.bottom-currentBounds.top;
- if (growLimits.top > kMinWindowHeight)
- growLimits.top = kMinWindowHeight;
-
- growLimits.right = kMaxWindowWidth;
- growLimits.bottom = kMaxWindowHeight;
-
- ODSLong newWindowSize = GrowWindow(pwindow, event->where, &growLimits);
- SizeWindow(pwindow, LoWord(newWindowSize), HiWord(newWindowSize), true);
-
- window->AdjustWindowShape(fEV);
-
- Rect r = pwindow->portRect;
- r.left = r.right - 15;
- r.top = r.bottom - 15;
- RgnHandle oldClip = nil;
- GetClip(oldClip = ODNewRgn());
- ClipRect(&r);
- DrawGrowIcon(pwindow);
- SetClip(oldClip);
- ODDisposeHandle((Handle)oldClip);
- }
- }
-
- //-------------------------------------------------------------------------------------
- // RealShell::HandleMouseDownInZoomBox
- //-------------------------------------------------------------------------------------
-
- void RealShell::HandleMouseDownInZoomBox(WindowPtr pwindow, ODSShort partcode, ODEventData* event)
- {
- if (TrackBox(pwindow, event->where, partcode))
- {
- TempODWindow window = kODNULL;
-
- if (fWindowState->IsODWindow(fEV,pwindow))
- window = fWindowState->AcquireODWindow(fEV,pwindow);
-
- GrafPtr port;
- GetPort(&port);
- SetPort(pwindow);
-
- ZoomWindow(pwindow, partcode, kODFalse);
-
- SetPort(port);
-
- if (window)
- window->AdjustWindowShape(fEV);
- }
- }
-
- //-------------------------------------------------------------------------------------
- // RealShell::UpdateMenus
- //-------------------------------------------------------------------------------------
-
- void RealShell::UpdateMenus()
- {
- ODIText* menuItem;
- TempODMenuBar menuBar = fWindowState->AcquireCurrentMenuBar(fEV);
- MenuHandle appleMenu = menuBar->GetMenu(fEV, kODAppleMenuID);
- MenuHandle editMenu = menuBar->GetMenu(fEV, kODEditMenuID);
- ODDocument* activeDocument = ODGetActiveDocument(fEV, fSession);
-
- fOptionKeyDownOnMenuBarClick = isOptionKeyDown();
-
- // Menu items which require resources:
- { CUsingLibraryResources r;
-
- // About Menu item
- this->RestoreMenuItem(appleMenu, kSHLMenuAbout, &fDefaultAboutMenuItem);
-
- //== Document-wide menu items
- Str255 targetName;
- if (activeDocument)
- {
- TempPlatformFile file =
- GetPlatformFileFromContainer(fEV, activeDocument->GetContainer(fEV));
-
- file->GetAsciiName( (char*)targetName, sizeof(targetName) );
- CToPascalString((char*)targetName);
- }
- else
- {
- targetName[0] = 0;
- }
- Str255 destString;
-
- // Delete Menu item
- ReplaceIntoString( kSHLDeleteItemTemplateStrID, targetName, kODNULL,
- destString );
- menuItem = CreateDefaultIText(destString);
- menuBar->SetItemString(fEV, kODCommandDeleteDocument, menuItem);
- DisposeIText(menuItem);
-
- // Save Menu item
- ReplaceIntoString( kSHLSaveItemTemplateStrID, targetName, kODNULL,
- destString );
- menuItem = CreateDefaultIText(destString);
- menuBar->SetItemString(fEV, kODCommandSave, menuItem);
- DisposeIText(menuItem);
-
- // Close Menu item
- if ( !isOptionKeyDown() ) // close the whole document
- {
- TempODWindow window = ODAcquireActiveWindow(fEV, fSession);
- ODPlatformWindow pwin = window ?
- window->GetPlatformWindow(fEV) : kODNULL;
- if ( pwin )
- GetWTitle( pwin, targetName );
- else
- targetName[0] = '\0';
- }
-
- ReplaceIntoString( kSHLCloseItemTemplateStrID, targetName, kODNULL,
- destString );
- menuItem = CreateDefaultIText(destString);
- menuBar->SetItemString(fEV, kODCommandClose, menuItem);
- DisposeIText(menuItem);
-
- // Part Info menu item
- menuItem = GetODITextInd(kSHLStrsID, kSHLStrIndMPartInfo);
- menuBar->SetItemString(fEV, kODCommandGetPartInfo, menuItem);
- DisposeIText(menuItem);
- }
- menuBar->EnableCommand(fEV, kODCommandAbout, kODTrue);
- menuBar->EnableCommand(fEV, kODCommandClose, kODTrue);
- menuBar->EnableCommand(fEV, kODCommandGetPartInfo, kODFalse);
-
- // Document Menu
-
- menuBar->EnableCommand(fEV, kODCommandNew, kODTrue);
- menuBar->EnableCommand(fEV, kODCommandOpen, kODFalse);
- menuBar->EnableCommand(fEV, kODCommandOpenDocument, kODTrue);
- menuBar->EnableCommand(fEV, kODCommandInsert, kODFalse);
- menuBar->EnableCommand(fEV, kODCommandDeleteDocument,
- ODDocumentHasWriteAccess(fEV, fSession, activeDocument));
-
- ODBoolean unsavedChanges = ODDocumentHasChanges(fEV, fSession, activeDocument);
- menuBar->EnableCommand(fEV, kODCommandSave, unsavedChanges);
- menuBar->EnableCommand(fEV, kODCommandSaveACopy, kODTrue);
- menuBar->EnableCommand(fEV, kODCommandRevert, unsavedChanges);
-
- menuBar->EnableCommand(fEV, kODCommandDraft, kODTrue);
- menuBar->EnableCommand(fEV, kODCommandDocumentInfo, kODTrue);
- menuBar->EnableCommand(fEV, kODCommandPageSetup, kODFalse);
- menuBar->EnableCommand(fEV, kODCommandPrint, kODFalse);
-
- // Edit Menu
-
- this->UpdateUndoMenus();
-
- menuBar->EnableCommand(fEV, kODCommandCut, kODFalse);
- menuBar->EnableCommand(fEV, kODCommandCopy, kODFalse);
- menuBar->EnableCommand(fEV, kODCommandPaste, kODFalse);
- menuBar->EnableCommand(fEV, kODCommandPasteAs, kODFalse);
- menuBar->EnableCommand(fEV, kODCommandClear, kODFalse);
- menuBar->EnableCommand(fEV, kODCommandSelectAll, kODFalse);
-
- menuBar->EnableCommand(fEV, kODCommandPreferences , kODFalse);
- menuBar->EnableCommand(fEV, kODCommandViewAsWin, kODFalse);
-
- if ( editMenu )
- this->RestoreMenuItem(editMenu, kSHLMenuPreferences, &fDefaultPrefsMenuItem);
-
- #if ODDebugMenu
- DebugOutputMode outMode = GetOutputMode();
- ODBoolean breakingOnThrow = BreakOnThrow(kODFalse);
- BreakOnThrow(breakingOnThrow); // Have to reset original value...
- menuBar->EnableCommand(fEV, kODCommandDBDumpObjects, outMode!=kNoOutput);
- menuBar->EnableCommand(fEV, kODCommandDBDumpBlocks, gTrackStackCrawls>0 && outMode!=kNoOutput);
- menuBar->CheckCommand(fEV, kODCommandDBMemValidation, gMemValidation>0);
- menuBar->CheckCommand(fEV, kODCommandDBHeapChecking, gHeapChecking>0);
- menuBar->EnableCommand(fEV, kODCommandDBLeakChecking, outMode!=kNoOutput);
- menuBar->CheckCommand(fEV, kODCommandDBLeakChecking, gLeakChecking>0);
- menuBar->EnableCommand(fEV, kODCommandDBDumpBlocksOnClose, outMode!=kNoOutput);
- menuBar->CheckCommand(fEV, kODCommandDBDumpBlocksOnClose, gDumpBlocksOnClose>0);
- menuBar->EnableCommand(fEV, kODCommandDBTrackStackCrawls, kODTrue);
- menuBar->CheckCommand(fEV, kODCommandDBTrackStackCrawls, gTrackStackCrawls>0);
- menuBar->CheckCommand(fEV, kODCommandDBLogStdout, outMode==kWriteToFile);
- menuBar->CheckCommand(fEV, kODCommandDBLogDebugWindow, outMode==kWriteToDebugWindow);
- menuBar->CheckCommand(fEV, kODCommandDBLogDebugStr, outMode==kGenerateDebugStrs);
- menuBar->CheckCommand(fEV, kODCommandDBBreakOnThrow, breakingOnThrow);
- menuBar->CheckCommand(fEV, kODCommandDBSOMTrace, SOM_TraceLevel!=0);
- #endif
-
- // Let the parts have the last crack at the menus.
- fWindowState->AdjustPartMenus(fEV);
- }
-
- //------------------------------------------------------------------------------
- // RealShell::CheckMenuBar
- //------------------------------------------------------------------------------
-
- void RealShell::CheckMenuBar()
- {
- ODBoolean shellHadMenuFocus = fShellHasMenuFocus;
- ODTypeToken menuFocus = fSession->Tokenize(fEV, kODMenuFocus);
- TempODFrame focusFrame = fSession->GetArbitrator(fEV)->AcquireFocusOwner(fEV, menuFocus);
- fShellHasMenuFocus = (focusFrame == kODNULL);
-
- if (fShellHasMenuFocus && !shellHadMenuFocus)
- {
- TempODMenuBar baseMenuBar = fWindowState->AcquireBaseMenuBar(fEV);
- if (baseMenuBar)
- baseMenuBar->Display(fEV);
- }
- }
-
- //------------------------------------------------------------------------------
- // RealShell::UpdateUndoMenus
- //------------------------------------------------------------------------------
-
- void RealShell::UpdateUndoMenus()
- {
- ODUndo* undo = fSession->GetUndo(fEV);
- ODPart* part;
- ODActionData actionData;
- ODActionType actionType;
- ODName actionLabel;
-
- ODVolatile(actionLabel);
- ODVolatile(actionData);
-
- actionLabel.text._buffer = kODNULL;
- actionData._buffer = kODNULL;
-
- TRY
- TempODMenuBar menuBar = fWindowState->AcquireCurrentMenuBar(fEV);
- MenuHandle editMenu = menuBar->GetMenu(fEV, kODEditMenuID);
-
- // these IsCommandRegistered calls are to prevent ResetUndoText from
- // being called with a null menu, which is what you get at least
- // in the EditorSetup case. Other cases might not be detected
-
- if (undo->PeekUndoHistory(fEV, &part, &actionData, &actionType,
- &actionLabel))
- {
- menuBar->EnableCommand(fEV, kODCommandUndo, kODTrue);
- menuBar->SetItemString(fEV, kODCommandUndo, &actionLabel);
- }
- else
- {
- menuBar->EnableCommand(fEV, kODCommandUndo, kODFalse);
- this->ResetUndoText(editMenu);
- }
-
- DisposeITextStruct(actionLabel);
- DisposeByteArrayStruct(actionData);
- actionLabel.text._buffer = kODNULL;
- actionData._buffer = kODNULL;
-
- if (undo->PeekRedoHistory(fEV, &part, &actionData, &actionType,
- &actionLabel))
- {
- menuBar->EnableCommand(fEV, kODCommandRedo, kODTrue);
- menuBar->SetItemString(fEV, kODCommandRedo, &actionLabel);
- }
- else
- {
- menuBar->EnableCommand(fEV, kODCommandRedo, kODFalse);
- this->ResetRedoText(editMenu);
- }
- CATCH_ALL
- if (actionLabel.text._buffer)
- DisposeITextStruct(actionLabel);
- if (actionData._buffer)
- DisposeByteArrayStruct(actionData);
- RERAISE;
- ENDTRY
-
- DisposeITextStruct(actionLabel);
- DisposeByteArrayStruct(actionData);
- }
-
-
- //-------------------------------------------------------------------------------------
- // RealShell::ResetUndoText
- //-------------------------------------------------------------------------------------
-
- void RealShell::ResetUndoText(MenuHandle editMenu)
- {
- if ( editMenu )
- this->RestoreMenuItem(editMenu, kSHLMenuUndo, &fDefaultUndoMenuItem);
- }
-
- //-------------------------------------------------------------------------------------
- // RealShell::ResetRedoText
- //-------------------------------------------------------------------------------------
-
- void RealShell::ResetRedoText(MenuHandle editMenu)
- {
- if ( editMenu )
- this->RestoreMenuItem(editMenu, kSHLMenuRedo, &fDefaultRedoMenuItem);
- }
-
- //-------------------------------------------------------------------------------------
- // New
- //-------------------------------------------------------------------------------------
-
- PlatformFile* RealShell::New()
- {
- // create another container, create a root part of the same kind and editor
- // as the root part of the active window
-
- TempODType rootPartType = kODNULL;
- TempODEditor editor = kODNULL;
- TempODName category = kODNULL;
- ODStorageUnit* psu = kODNULL;
- PlatformFile* newFile = new PlatformFile();
-
- TempODWindow window = ODAcquireActiveWindow(fEV, fSession);
- if (window)
- {
- TempODPart part = window->GetRootFrame(fEV)->AcquirePart(fEV);
- ASSERT((ODPart*)part != kODNULL, kODErrNoDraftProperties);
- // !!!!! Should probably have its own errorcode, even though the user
- // error message will be the same.
- category = ODGetCategory(fEV, part, fSession->GetNameSpaceManager(fEV));
- psu = part->GetStorageUnit(fEV);
- }
-
- if (psu &&
- psu->Exists(fEV, kODPropContents, (ODValueType)kODNULL, (ODValueIndex)kODNULL))
- {
- psu->Focus(fEV, kODPropContents, kODPosSame, (ODValueType)kODNULL,1, kODPosFirstSib);
- rootPartType = psu->GetType(fEV);
- editor = (ODEditor)ODGetISOStrProp(fEV, psu, kODPropPreferredEditor, kODEditor, kODNULL, kODNULL);
-
- TempPlatformFile file = GetPlatformFileFromContainer(fEV,
- psu->GetDraft(fEV)->GetDocument(fEV)->GetContainer(fEV));
- newFile->SpecifyFromFile(file);
- }
-
- {
- ODContainer* container;
- CreateUntitledContainer(kODNULL, &container, newFile, category);
- TempODContainer newContainer = container;
- ODNewDocument(fEV, newContainer, rootPartType, editor);
- }
-
- this->OpenAnotherFile(newFile, kODNULL, kODTrue, kODTrue); // Both are true because this is a new unsaved doc
- return newFile;
- }
-
- //-------------------------------------------------------------------------------------
- // New File(Name/Spec)
- //-------------------------------------------------------------------------------------
-
- ODStatic void CreateNewUntitledFile(PlatformFile* newFile,
- char* fileNameSeed)
- {
- Str255 fileName; // !!!! MUST BE AN ARRAY IN ORDER TO WORK (sizeof used below)
-
- if (newFile->IsStationery())
- {
- newFile->GetAsciiName((char*)fileName, sizeof(fileName)-1);
- }
- else if (fileNameSeed != kODNULL)
- {
- strncpy((char*)fileName, fileNameSeed, sizeof(fileName)-1);
- }
- else
- {
- strcpy((char*)fileName, "");
- }
-
- CToPascalString((char*)fileName);
- if ( fileName[0] > kODMaxFileNameSize )
- (void)ClipStringToBytes( fileName, kODMaxFileNameSize, smSystemScript );
- PascalToCString(fileName);
-
- newFile->SetAsciiName((char*)fileName);
-
- CreateNewFile(newFile, kODForceNewName);
- }
-
- void CreateNewFile(PlatformFile* newFile, ODBoolean forceNewName)
- {
- ODSLong seed = 0;
- ODULong err = noErr;
-
- ODSByte prefixName[kODMaxFileNameSize+1];
- newFile->GetAsciiName(prefixName, kODMaxFileNameSize);
- prefixName[kODMaxFileNameSize] = 0;
- ODUShort prefixLen = strlen(prefixName);
-
- ODSByte newName[kODMaxFileNameSize+1];
- strcpy(newName,prefixName);
-
- ODFileSpec fs = newFile->GetFileSpec();
-
- while (GetVolumeWritableSpace(&fs, kODNULL) < kSpaceNeededForNewDocument)
- {
-
- THROW_IF_ERROR(FindFolder(kOnSystemDisk, kDesktopFolderType, kCreateFolder,
- &(fs.vRefNum), &(fs.parID)));
-
- if (GetVolumeWritableSpace(&fs, &err) >= kSpaceNeededForNewDocument)
- break;
-
- THROW_IF_ERROR(err);
- THROW(kODErrSystemVolumeIsFull);
-
- // It would be nice to try other volumes as well, like:
- // iterate through local non-removable volumes
- // if enough space on one of those, then use it & break; break;
- // iterate through local removable volumes
- // if enough space on one of those, then use it & break; break;
- // iterate through remote volumes
- // if enough space on one of those, then use it & break; break;
-
- // THROW(kODErrAllWritableVolumesAreFull);
-
- }
- newFile->Specify(&fs);
- newFile->UniquifyName( kODNoResourceID /*kConcatDefaultNameNoNumStrID*/, kODNULL,
- kSHLNewFilenameTemplateStrID, kODNULL, 1, kSpecifyNewNameOnly, forceNewName );
-
- } // CreateNewFile
-
- void RealShell::CreateUntitledContainer(ODDocument** documentPtr,
- ODContainer** containerPtr, PlatformFile* newFile, ODName* fileNameSeed)
- {
- char* cfnSeed = kODNULL;
- if (fileNameSeed != kODNULL)
- cfnSeed = GetITextCString(fileNameSeed, kODNULL);
-
- CreateNewUntitledFile(newFile, cfnSeed);
-
- ODDeleteObject(cfnSeed);
-
- newFile->Create(kODShellSignature, kODShellSignature, 0);
-
- ODULong refNumCount;
- ODSShort* refNums;
- if (documentPtr)
- {
- GetLocalPaths(&(newFile->GetFileSpec()), kDataFork,
- &refNumCount, &refNums);
- }
-
- (*containerPtr) = CreateFileContainer(fEV, fSession, &(newFile->GetFileSpec()));
-
- if (documentPtr)
- {
- *documentPtr = (*containerPtr)->AcquireDocument(fEV, kODDefaultDocument); // -- TÇ: documentPtr acquires a document
- }
- }
-
- void RealShell::CreateTitledContainer(ODDocument** documentPtr,
- ODContainer** containerPtr, PlatformFile* newFile, char* newName)
- {
- newFile->SetAsciiName(newName);
-
- CreateNewFile(newFile, kODTryCurrentName);
-
- newFile->Create(kODShellSignature, kODShellSignature, 0);
-
- ODULong refNumCount;
- ODSShort* refNums;
- if (documentPtr)
- {
- GetLocalPaths(&(newFile->GetFileSpec()), kDataFork,
- &refNumCount, &refNums);
- }
-
- (*containerPtr) = CreateFileContainer(fEV, fSession, &(newFile->GetFileSpec()));
-
- if (documentPtr)
- {
- *documentPtr = (*containerPtr)->AcquireDocument(fEV, kODDefaultDocument); // -- TÇ: documentPtr acquires a document
- }
- }
-
- //------------------------------------------------------------------------------
- // Temporary File(Name/Spec)
- //------------------------------------------------------------------------------
-
- void CreateTempName(short seed, Str255 name, ODBoolean isFile)
- {
- // Don't modify this one!
- char* nmSeed = isFile? "ODShellTempFile" : "ODShellTempFolder";
- strcpy((char*)name, nmSeed);
-
- char theNum[10];
- NumToString(seed, (StringPtr)theNum);
- WASSERT(theNum[0] <= 5);
- p2cstr((StringPtr)theNum);
-
- strcat((char*)name, theNum);
- c2pstr((char *)name);
- }
-
-
- void RealShell::CreateUniqueTmpFolderForFile(ODFileSpec* result,
- Str63 fileName)
- {
- Str255 myName;
- ODSLong myDirID;
- ODSShort myVRef;
- GetTempFolder(&myVRef, &myDirID);
-
- OSErr err;
- short limit = kMaxUniqueNameTries;
- while ( --limit )
- {
- CreateTempName( fUniqueNameSeed++, myName, kODFalse );
- long createdDirID;
- err = DirCreate( myVRef, myDirID, myName,
- &createdDirID );
- if ( err == noErr )
- {
- FSMakeFSSpec(myVRef, createdDirID, fileName, result);
- return;
- }
- }
- THROW( err );
- }
-
- void GetTempFolder(ODSShort* VRef,ODSLong* DirID)
- {
- FindFolder(0, kTemporaryFolderType, kCreateFolder,VRef,DirID);
- }
-
- //-------------------------------------------------------------------------------------
- // CopyResources -- copy the document resources from one file to another
- //-------------------------------------------------------------------------------------
-
- ODStatic void CopyResources(PlatformFile* srcFile, PlatformFile* dstFile)
- {
- CUsingLibraryResources r;
- VerifyDocumentStub(&(dstFile->GetFileSpec()), kODNULL);
- // Makes sure to copy resources into the new document.
-
- ODULong sizeOfResource;
- for(ODUShort i=0; i<= 1; i++) {
- ODPtr sizeRes = srcFile->ReadResourcePtr(kSIZERsrcType, i, &sizeOfResource);
- if (sizeRes != kODNULL) {
- dstFile->WriteResourcePtr(kSIZERsrcType, i, sizeRes, sizeOfResource);
- ODDisposePtr(sizeRes);
- }
- }
- }
-
- //-------------------------------------------------------------------------------------
- // Open
- //-------------------------------------------------------------------------------------
-
- void RealShell::OpenFile(PlatformFile* file)
- {
- // if the file is a stationery seed,
- // produce mature stationery in the Stationery folder and quit
- // else create a new container if the given file is stationery
- // else open the container and document and current draft and install ShellPlugIns
- // note: file is not consumed and is presumed to be disposed of by the caller
-
- WatchCursor();
- ODPlatformType fileType = file->GetPlatformType();
-
- ODFileSpec fs = file->GetFileSpec();
-
- // ASSERT(the document is at the end of the resource chain)
-
- ODSShort numSeeds = Count1Resources(kDocSeedResType);
- if (numSeeds > 0)
- {
- FindStationeryFolder(&(fs.vRefNum), &(fs.parID));
- file->Specify(&fs);
-
- for (;numSeeds;--numSeeds)
- {
- Handle seedEditor;
- ODContainer* container;
- short unusedID;
- ResType unusedType;
- Str255 editorName;
-
- seedEditor = Get1IndResource(kDocSeedResType, numSeeds);
- TempODType editor = (ODType)ODNewPtr(GetHandleSize(seedEditor),0);//•minor leak [FIXED]
- HLock(seedEditor); //• unnecessary; CFM libs have no segments
- strcpy((char*)editor, (char*)*seedEditor);
- HUnlock(seedEditor);
- GetResInfo(seedEditor, &unusedID, &unusedType, editorName);
- if (editorName[0] > 31)
- ClipStringToBytes( editorName, 31, smCurrentScript );
- PascalToCString(editorName);
- CreateTitledContainer(kODNULL, &container, file, (char*)editorName);//•minor leak on exception [FIXED]
- TempODContainer tempContainer = container; // ensures it's released
-
- ODNewDocument(fEV, container, kODNULL, editor);
- file->SetStationery(kODTrue);
-
- RemoveResource(seedEditor);
- }
-
- UpdateResFile(CurResFile());
- fDispatcher->Exit(fEV);
- }
- else
- {
- PlatformFile* newFile = kODNULL;
- ODVolatile(newFile);
- if (file->GetPlatformCreator() == kODShellSignature)
- {
- if (file->IsStationery())
- {
- TRY
- ODContainer* container = kODNULL;
- ODDocument* document = kODNULL;
- ODDraft* draft = kODNULL;
- ODAcquireCtrDocTopDraft(fEV, fSession, file, &container, &document, &draft);
- TempODContainer sContainer = container;
- TempODDocument sDocument = document;
- TempODDraft sDraft = draft;
-
- newFile = new PlatformFile;
- newFile->SpecifyFromFile(file);
-
- container = kODNULL; document = kODNULL;
- CreateUntitledContainer(&document, &container, newFile);
- TempODContainer newContainer = container;
- TempODDocument newDocument = document;
-
- CopyResources(file, newFile);
- newDocument->SetBaseDraftFromForeignDraft(fEV, sDraft);
- TempODDraft newDraft = newDocument->AcquireBaseDraft(fEV, kODDPExclusiveWrite);
- {
- TempODStorageUnit su = newDraft->AcquireDraftProperties(fEV);
- ODResetDateModByInfo(fEV, su);
- }
- {
- TempODStorageUnit su = ODAcquireRootPartSUOfDraft(fEV, newDraft);
- ODResetDateModByInfo(fEV, su);
- }
- ODSetIsUnsavedNewDocument(fEV, newDraft);
- newDraft->Externalize(fEV);
-
- newFile->SetPlatformType(file->GetPlatformType());
-
- { TempODDocumentName name(newFile->GetName());
- newDocument->SetName(fEV, name);
- }
-
- file = newFile;
- CATCH_ALL
- if (newFile)
- {
- TRY
- newFile->MoveToTrash();
- CATCH_ALL
- ENDTRY
- }
- RERAISE;
- ENDTRY
- }
-
- }
- else
- {
- // translate fileType into an OpenDoc kind
- TempODType theKind = fSession->GetTranslation(fEV)->
- GetISOTypeFromPlatformType(fEV, fileType, kODPlatformFileType);
-
- // Check to see if fileType is supported by an OpenDoc Editor
- ODEditor theEditor = fSession->GetBinding(fEV)->ChooseEditorForPart( fEV, kODNULL, theKind );
- if (!theEditor)
- {
- fDispatcher->Exit(fEV);
- THROW( kODErrCouldNotBindForeignDocument );
- }
-
- // create new File
- newFile = new PlatformFile(); //• leak on exception
- newFile->SpecifyFromFile(file);
- Str255 fileName;
- Str255 newName;
- newFile->GetAsciiName( (char*)fileName, kODMaxFileNameSize );
- CToPascalString((char*)fileName);
- { CUsingLibraryResources r;
- ReplaceIntoString(kSHLPreODDocNameStrID, fileName,
- kODEmptyPString, newName);
- }
- PascalToCString(newName);
-
- // Need actual object pointers because of CreateTitledContainer calling conventions
- ODDocument* document = kODNULL;
- ODContainer* container = kODNULL;
-
- CreateTitledContainer(&document, &container, newFile, (char*)newName);
- // Now immediately assign to tempobj's to be exception safe.
- TempODContainer newContainer = container;
- TempODDocument newDocument = document;
-
- HFSFlavor hfsFlavor;
- hfsFlavor.fileType = fileType;
- hfsFlavor.fileCreator = file->GetPlatformCreator();
- hfsFlavor.fdFlags = file->GetFInfoFlags();
- hfsFlavor.fileSpec = file->GetFileSpec();
-
- ((ODUByte*)(&fileType))[0] = kODPlatformKindFileChar1;
- newFile->SetPlatformType(fileType);
-
- TempODDraft newDraft = newDocument->AcquireBaseDraft(fEV, kODDPExclusiveWrite);
- TempODStorageUnit su = newDraft->AcquireDraftProperties(fEV);
- ODResetDateModByInfo(fEV, su);
-
- TempODStorageUnit rootPartSU = newDraft->CreateStorageUnit(fEV);
- ODSetRootPartSUOfDraft(fEV, newDraft, rootPartSU);
-
- // create contents prop/ value for kODApplehfs
- ODSUAddPropValue(fEV, rootPartSU, kODPropContents, kODApplehfs);
- StorageUnitSetValue(rootPartSU, fEV, sizeof( hfsFlavor ), &hfsFlavor);
- rootPartSU->AddValue(fEV, theKind);
-
- ODSetISOStrProp(fEV, rootPartSU, kODPropPreferredEditor, kODEditor, theEditor);
-
- ODSetIsUnsavedNewDocument(fEV, newDraft);
- newDraft->Externalize(fEV);
- file = newFile;
- }
-
- ODDraft* topdraft = kODNULL;
- ODVolatile(topdraft);
-
- TRY
- // Open the document
- topdraft = ODOpenFileDocument(fEV, fSession, file, kODDPExclusiveWrite);
- this->InstallShellPlugIns(topdraft);
-
- ODOpenDraft(fEV, fSession, topdraft);
- ODReleaseObject(fEV, topdraft);
-
- fDispatcher = fSession->GetDispatcher(fEV);
- fWindowState = fSession->GetWindowState(fEV);
-
- ODFileSpec fileFSSpec = file->GetFileSpec();
-
- LMSetSFSaveDisk(-(fileFSSpec.vRefNum));
- LMSetCurDirStore(fileFSSpec.parID);
- ODDeleteObject(newFile);
- CATCH_ALL
- this->CheckFreeMemory();
- if (topdraft)
- {
- ODDocument* document = topdraft->GetDocument(fEV);
- ODSafeReleaseObject(topdraft);
- if (ODCloseDocument(fEV, fSession, document))
- fDispatcher->Exit(fEV);
- }
- this->SetAEError(ErrorCode());
- ENDTRY
- ArrowCursor();
- }
- } // RealShell::OpenFile
-
- //------------------------------------------------------------------------------
- // RealShell::OpenAnotherFile
- //------------------------------------------------------------------------------
-
- void RealShell::OpenAnotherFile(PlatformFile* file,
- AEDescList* replyInfo,
- ODBoolean deleteOnFailure,
- ODBoolean unsavedDoc)
- {
- // launch another document stub to open the passed in PlatformFile
- OSErr err = noErr;
- ODFileSpec theDocument = file->GetFileSpec();
- if (WasLaunchedThenActivate(&theDocument, kAEOpenDocuments, err))
- return;
-
- ODSLong savedRefNum;
- BeginUsingLibraryResources(savedRefNum);
- AEDesc docDesc;
- ProcessSerialNumber psn;
- err = AECreateDesc( typeFSS, &theDocument, sizeof(theDocument),
- &docDesc );
- if ( !err )
- {
- err = VerifyAndLaunchDocumentStub(&docDesc, replyInfo, &psn,
- kAEOpenDocuments, kODNULL, unsavedDoc);
- AEDisposeDesc( &docDesc );
- }
- EndUsingLibraryResources(savedRefNum);
- if ( err ) {
- if( deleteOnFailure )
- file->Delete();
- THROW( err );
- } else if( deleteOnFailure ) {
- // Remember PSN and spec in case launch fails; CFM will send us an error and
- // we can then delete the new file. See HandleLaunchFailedEvent...
- fLastNewDocPSN = psn;
- fLastNewDocSpec= file->GetFileSpec();
- }
- }
-
- //------------------------------------------------------------------------------
- // OpenFileFilter
- //
- // Return true (don't show this item) for invisible files and folders
- //
- // Addendum: There appears to be no way to filter out invisible folders, since
- // thie function is only passed files. Oh well. Leaving code in anyway in case
- // this changes.
- //------------------------------------------------------------------------------
-
- static pascal Boolean OpenFileFilter(CInfoPBPtr fileInfo)
- {
- if (fileInfo->hFileInfo.ioFlAttrib & ioDirMask) // FOLDER
- {
- if (fileInfo->dirInfo.ioDrUsrWds.frFlags & fInvisible)
- return true;
- }
- else // FILE
- {
- if (fileInfo->hFileInfo.ioFlFndrInfo.fdFlags & fInvisible)
- return true;
- }
-
- return false;
- }
-
- //------------------------------------------------------------------------------
- // RealShell::OpenStdFile
- //------------------------------------------------------------------------------
-
- void RealShell::OpenStdFile()
- {
- // call display StdFile (with all documents) and open document in a new shell
- ArrowCursor();
- StandardFileReply sfReply;
- SFTypeList sfTypes;
-
- fWindowState->DeactivateFrontWindows(fEV);
-
- FileFilterUPP openFileFilterUPP = NewFileFilterProc(OpenFileFilter);
- StandardGetFile((FileFilterUPP)openFileFilterUPP, -1, sfTypes, &sfReply);
- DisposeRoutineDescriptor(openFileFilterUPP);
-
- fWindowState->ActivateFrontWindows(fEV);
-
- if (sfReply.sfGood)
- {
- PlatformFile* file = new PlatformFile();
- file->Specify(&(sfReply.sfFile));
- if (file->GetPlatformCreator() == kODShellSignature &&
- file->GetPlatformType() != 'APPL') // not the launcher
- {
- this->OpenAnotherFile(file);
- }
- else
- {
- THROW_IF_ERROR( SendFinderODOCEvent( &sfReply.sfFile ) );
-
- // Fix #1221901:
- // else (if creator≠ kODShellSignature)
- // 'appl' = launch application
- // else 'snd ' = play sound
- // else 'cdev' = open control panel
- // else use MEO,desktop database to find appropriate application to use,
- // then launch application with document
- }
- delete file;
- }
- }
-
- //-------------------------------------------------------------------------------------
- // DoesUserCancelClose
- //
- // To do: Fix flow of control
- //-------------------------------------------------------------------------------------
-
- ODBoolean RealShell::DoesUserCancelClose(ODDocument* document, DescType saveOptions)
- {
- // asks user "Save changes before closing? Discard Changes, Cancel , Save"
- ODBoolean stillSave;
- switch(saveOptions)
- {
- case kAEAsk:
- {
- if (AEInteractWithUser(kNoTimeOut, NULL, NULL) != noErr)
- return kODTrue;
- ArrowCursor();
- char fileName[256];
- ODGetDocumentFileName(fEV, document, &(fileName[0]));
- CToPascalString(fileName);
-
-
- ODSShort btnClicked;
- if (ODIsTempDocument(fEV, fSession, document))
- {
- if (ODIsUnsavedNewDocument(fEV, fSession, document))
- btnClicked = kSHLscNo;
- else
- btnClicked = kSHLscOK;
- }
- else
- {
- ODSLong savedRefNum;
- BeginUsingLibraryResources(savedRefNum);
- ParamText((unsigned char const *)fileName, kODEmptyPString,
- kODEmptyPString, kODEmptyPString);
- fWindowState->DeactivateFrontWindows(fEV);
- TRY
- {
- DialogPtr askSaveDlg = kODNULL;
- askSaveDlg = ODGetNewDialog( fEV, kSHLsvChanges, fSession, kODTrue );
- THROW_IF_NULL( askSaveDlg );
- ODUseCommandKeyStringsResource( kSHLsvChangesCmdKeyStrs );
- ::ShowWindow( askSaveDlg );
- // FIX_THIS_PLACE
- ::ModalDialog( GetODButtonKeyFilterProc(), &btnClicked );
- ::DisposeDialog( askSaveDlg );
- }
- CATCH_ALL
- {
- btnClicked = kSHLscCancel; // Cancel the close
- }
- ENDTRY
-
- fWindowState->ActivateFrontWindows(fEV);
-
- EndUsingLibraryResources(savedRefNum);
- }
- if (btnClicked == kSHLscCancel)
- return kODTrue;
- else if (btnClicked == kSHLscNo &&
- ODIsUnsavedNewDocument(fEV, fSession, document))
- {
- TempPlatformFile file =
- GetPlatformFileFromContainer(fEV, document->GetContainer(fEV));
- file->MoveToTrash();
- }
-
- stillSave = (btnClicked == kSHLscOK);
- }
- break;
- case kAEYes:
- stillSave = kODTrue;
- break;
- case kAENo:
- stillSave = kODFalse;
- break;
- default:
- THROW(errAETypeError);
- }
-
- if (stillSave)
- {
- if (this->Save(document, kODTrue))
- ;
- else // The user canceled the Save As dialog, which cancels the close
- return kODTrue;
- }
- return kODFalse;
- }
-
-
- void RealShell::CloseWindow(ODPlatformWindow pwindow, DescType saveOptions)
- {
- if (pwindow==kODNULL)
- {
- fDispatcher->Exit(fEV);
- return;
- }
-
- if (!fWindowState->IsODWindow(fEV,pwindow))
- {
- ASSERT(fWindowState->IsODWindow(fEV,pwindow), kODErrClosingNonODWindow);
- return;
- }
-
- ODWindow* window = fWindowState->AcquireODWindow(fEV,pwindow);
- if (!window)
- return;
-
- ODDraft* draft = window->GetDraft(fEV);
- ODDocument* document = draft->GetDocument(fEV);
- ODBoolean isOnlyTopDraftWindow =
- window->IsRootWindow(fEV) && (fWindowState->GetRootWindowCount(fEV,draft) == 1) &&
- (!(document->Exists(fEV, kODNULLID, draft, kODPosFirstAbove)));
-
- if (isOnlyTopDraftWindow &&
- ODDraftHasWriteAccess(fEV, draft) &&
- (draft->ChangedFromPrev(fEV) || ODIsUnsavedNewDocument(fEV, fSession, document)))
- {
- if (saveOptions == kAEYes)
- {
- ODSaveDocument(fEV, fSession, document);
- }
- else
- {
- ODReleaseObject(fEV, window); // balances AcquireODWindow above
-
- if (this->DoesUserCancelClose(document, saveOptions))
- return;
-
- window = fWindowState->AcquireODWindow(fEV,pwindow); // reacquire because user did not cancel close
- // NOTE: If the user SAVED the document inside the DoesUserCancelClose
- // call above for the first time, (thereby using StdFile), and to a
- // different volume, then DoesUserCancelClose did NOT reopen the document,
- // and pwindow is no longer a valid WindowPtr. Therefore, the windowstate
- // does not find it, and return kODNULL which causes the same code
- // execution as if the return statement above was executed.
- }
- }
-
- if (window)
- if (ODReleaseCloseWindow(fEV, fSession, window)) // balances AcquireODWindow above
- fDispatcher->Exit(fEV);
- }
-
- //------------------------------------------------------------------------------
- // RealShell::CloseDocument
- //
- // Result of true means that document was closed (or close was attempted).
- // Result of false means that the process was cancelled.
- //------------------------------------------------------------------------------
-
- ODBoolean RealShell::CloseDocument(ODDocument* document, DescType saveOptions)
- {
- ODDraft* draft = ODGetTempDraftFromOpenDocument(fEV, fSession, document);
- ODBoolean result = kODTrue;
-
- if (draft != kODNULL &&
- ODDraftHasWriteAccess(fEV, draft) &&
- (draft->ChangedFromPrev(fEV) || ODIsUnsavedNewDocument(fEV, fSession,
- document)))
- {
- if (this->DoesUserCancelClose(document, saveOptions))
- result = kODFalse;
- }
- if (result == kODTrue)
- {
- if (ODCloseDocument(fEV, fSession, document))
- fDispatcher->Exit(fEV);
- }
-
- return result;
- }
-
- //------------------------------------------------------------------------------
- // RealShell::DeleteDocument
- //------------------------------------------------------------------------------
-
- void RealShell::DeleteDocument(ODDocument* document)
- {
- // First, ask the user if they are sure they want to delete!
- if (!isOptionKeyDown())
- {
- ArrowCursor();
-
- char fileName[256];
- ODGetDocumentFileName(fEV, document, &(fileName[0]));
- CToPascalString(fileName);
-
- ODSLong savedRefNum;
- BeginUsingLibraryResources(savedRefNum);
-
- ParamText(kODEmptyPString, (unsigned char const *)fileName,
- kODEmptyPString, kODEmptyPString);
-
- fWindowState->DeactivateFrontWindows(fEV);
-
- ODSShort btnClicked;
- TRY
- {
- DialogPtr askRevertDlg = kODNULL;
- askRevertDlg = ODGetNewDialog( fEV, kSHLDeleteDLOG, fSession, kODTrue );
- THROW_IF_NULL( askRevertDlg );
- ODUseCommandKeyStringsResource( kSHLDeleteDLOGCmdKeyStrs );
- ::ShowWindow( askRevertDlg );
- ::ModalDialog( GetODButtonKeyFilterProc(), &btnClicked );
- ::DisposeDialog( askRevertDlg );
- }
- CATCH_ALL
- {
- btnClicked = kSHLscCancel; // Cancel the delete
- }
- ENDTRY;
-
- fWindowState->ActivateFrontWindows(fEV);
-
- EndUsingLibraryResources(savedRefNum);
- if (!(kSHLscOK == btnClicked))
- return;
- }
-
- TempPlatformFile
- currentFile = GetPlatformFileFromContainer(fEV, document->GetContainer(fEV));
-
- ODSaveDocument(fEV, fSession, document);
- if (ODCloseDocument(fEV, fSession, document))
- fDispatcher->Exit(fEV);
-
- currentFile->MoveToTrash();
- }
-
- //-------------------------------------------------------------------------------------
- // Save
- //-------------------------------------------------------------------------------------
-
- ODBoolean RealShell::Save(ODDocument* document, ODBoolean isClosing)
- {
- if (ODIsUnsavedNewDocument(fEV, fSession, document))
- {
- StandardFileReply reply;
- Str255 fileName;
- ODGetDocumentFileName(fEV, document, (char*)&(fileName[0]));
- CToPascalString((char*)fileName);
-
- Str255 msg;
- { CUsingLibraryResources r;
- GetIndString(msg, kSHLStrsID, kSHLStrIndDSaveAs);
- }
-
- TempPlatformFile
- currentFile = GetPlatformFileFromContainer(fEV, document->GetContainer(fEV));
-
- // Need to rename file on disk briefly to avoid erroneous "Replace?" dialog
-
- // $$$$$ DOES NOT ACCOUNT FOR THE CASE WHERE THE filename+" " already exists !!!!!!
-
- FSSpec currentFSSpec = currentFile->GetFileSpec();
- if (currentFSSpec.name[0] < kODMaxFileNameSize)
- currentFSSpec.name[++currentFSSpec.name[0]] = 0x20;
- else
- --currentFSSpec.name[0];
-
- TRY
- currentFile->Rename(currentFSSpec.name);
- CATCH_ALL
- WARN("Unable to rename to avoid replace dialog. One replace dialog coming up!");
- ENDTRY
-
- // This would be cleaner, but not optimal
- // currentFile->UniquifyName(,,,,kRenameInPlace);
-
- ODDraft* draft = ODGetTempDraftFromOpenDocument(fEV, fSession, document);
- ODBoolean isStationery =
- this->AskUserWhereToPutIt(draft, fileName, msg, &reply );
-
- if (!reply.sfGood)
- {
- TRY
- currentFile->Rename(fileName);
- CATCH_ALL
- ENDTRY
- return kODFalse;
- }
-
- {
- // This assumes that the front window is the one being saved.
- // This might not be true for scripting, although it is right now
- // since we can only script the front window.
- TempODWindow window = fWindowState->AcquireFrontRootWindow(fEV);
- ODSetIsStationery(fEV, window->GetRootFacet(fEV)->GetFrame(fEV), isStationery);
- }
-
- TempPlatformFile file = new PlatformFile();
- file->Specify(&reply.sfFile);
-
- if (file->IsEqualTo(currentFile))
- ; // do nothing, we'll save down below right ontop of the current document.
- else
- {
- if (reply.sfReplacing)
- {
- TRY
- file->Delete();
- CATCH_ALL
- THROW(kODErrCannotSaveAsOntoBusyDoc);
- ENDTRY;
- }
-
- if (reply.sfFile.vRefNum == currentFile->GetFileSpec().vRefNum)
- {
- currentFile->MoveRename(&(reply.sfFile), kODFalse);
- }
- else
- {
- if (!isClosing)
- this->ShowSaveDiffVolDialog();
-
- ODSaveDocument(fEV, fSession, document);
- ODBoolean wasLastDocument = ODCloseDocument(fEV, fSession, document);
- file->CopyFrom(currentFile);
- currentFile->Delete();
- if (!isClosing)
- {
- ODDraft* topdraft = ODOpenFileDocument(fEV, fSession, file, kODDPExclusiveWrite);
- document = topdraft->GetDocument(fEV);
- this->InstallShellPlugIns(topdraft);
-
- ODOpenDraft(fEV, fSession, topdraft);
- this->CloseSaveDiffVolDialog();
-
- ODReleaseObject(fEV, topdraft);
-
- fDispatcher = fSession->GetDispatcher(fEV);
- fWindowState = fSession->GetWindowState(fEV);
- }
- else
- {
- if (wasLastDocument)
- fDispatcher->Exit(fEV);
- }
-
- LMSetSFSaveDisk(-(reply.sfFile.vRefNum));
- LMSetCurDirStore(reply.sfFile.parID);
- }
- }
- }
-
- ODSetIsTempDocument(fEV, ODGetTempDraftFromOpenDocument(fEV, fSession, document), kODFalse);
- ODSaveDocument(fEV, fSession, document);
- return kODTrue;
- } // RealShell::Save
-
- void RealShell::ShowSaveDiffVolDialog( )
- {
- if( !fSaveDiffVolDialog ) {
- CUsingLibraryResources r;
- fSaveDiffVolDialog = ::GetNewDialog(kSHLSaveDiffVolDialogID,kODNULL,(WindowPtr)-1L);
- ::ShowWindow(fSaveDiffVolDialog);
- ::DrawDialog(fSaveDiffVolDialog);
- }
- }
-
- void RealShell::CloseSaveDiffVolDialog( )
- {
- if( fSaveDiffVolDialog ) {
- CUsingLibraryResources r;
- ::DisposeDialog(fSaveDiffVolDialog);
- fSaveDiffVolDialog = kODNULL;
- }
- }
-
- //-------------------------------------------------------------------------------------
- // Save A Copy
- //-------------------------------------------------------------------------------------
-
- pascal void DrawSmallIcon(DialogPtr theDialog, short theItem)
- {
- short itemHit;
- Handle scratchHandle;
- Rect scratchRect;
-
- GetDialogItem(theDialog, theItem, &itemHit, &scratchHandle, &scratchRect);
-
- (void) PlotIconID (&scratchRect, atNone, ttNone,
- theItem == kSHLSaCDocumentIconItem ? kSHLSaCDocumentIconID : kSHLSaCStationeryIconID);
- }
-
- pascal short SaveCopyDlgHook(short item, DialogPtr theDialog, void *saveDataPtr)
- {
- short itemHit;
- Handle scratchHandle;
- Rect scratchRect;
- ODSShort translateItem = 0;
- ODSShort currentKindItem = 0;
-
- UserItemUPP drawSmallIconUPP = ((SaveCopyStruct*)saveDataPtr)->iconUPP;
-
- if ( ((WindowPeek)theDialog)->refCon == sfMainDialogRefCon )
- switch (item) {
- case sfHookFirstCall:
- GetDialogItem(theDialog, kSHLSaCDocumentIconItem, &itemHit, &scratchHandle, &scratchRect);
- SetDialogItem(theDialog, kSHLSaCDocumentIconItem, itemHit, (Handle) drawSmallIconUPP, &scratchRect);
-
- GetDialogItem(theDialog, kSHLSaCStationeryIconItem, &itemHit, &scratchHandle, &scratchRect);
- SetDialogItem(theDialog, kSHLSaCStationeryIconItem, itemHit, (Handle) drawSmallIconUPP, &scratchRect);
-
- GetDialogItem(theDialog, kSHLSaCDocumentRadioBtn, &itemHit, &scratchHandle, &scratchRect);
- SetControlValue( (ControlHandle) scratchHandle, !((SaveCopyStruct*)saveDataPtr)->makeStationery);
-
- GetDialogItem(theDialog, kSHLSaCStationeryRadioBtn, &itemHit, &scratchHandle, &scratchRect);
- SetControlValue( (ControlHandle) scratchHandle, ((SaveCopyStruct*)saveDataPtr)->makeStationery);
-
- GetDialogItem(theDialog, kSHLSaCKindPopupItem, &itemHit, &scratchHandle, &scratchRect);
- MenuHandle kindMenu = GetMenu(kSHLSaCKindPopupMenu);
- THROW_IF_NULL(kindMenu);
-
- InitKindsPopup(((SaveCopyStruct*)saveDataPtr)->kindList,
- ((SaveCopyStruct*)saveDataPtr)->partKind,
- (ControlHandle)scratchHandle,
- ¤tKindItem, kindMenu, &translateItem,
- ((SaveCopyStruct*)saveDataPtr)->session);
- break;
-
- case kSHLSaCDocumentRadioBtn :
- GetDialogItem(theDialog, kSHLSaCDocumentRadioBtn, &itemHit, &scratchHandle, &scratchRect);
- SetControlValue( (ControlHandle) scratchHandle, 1);
- GetDialogItem(theDialog, kSHLSaCStationeryRadioBtn, &itemHit, &scratchHandle, &scratchRect);
- SetControlValue( (ControlHandle) scratchHandle, 0);
-
- break;
-
- case kSHLSaCStationeryRadioBtn :
- GetDialogItem(theDialog, kSHLSaCDocumentRadioBtn, &itemHit, &scratchHandle, &scratchRect);
- SetControlValue( (ControlHandle) scratchHandle, 0);
- GetDialogItem(theDialog, kSHLSaCStationeryRadioBtn, &itemHit, &scratchHandle, &scratchRect);
- SetControlValue( (ControlHandle) scratchHandle, 1);
-
- break;
-
- case sfHookLastCall :
- /* check value of radio buttons and save accordingly */
- GetDialogItem(theDialog, kSHLSaCStationeryRadioBtn, &itemHit, &scratchHandle, &scratchRect);
- ((SaveCopyStruct*)saveDataPtr)->makeStationery = GetControlValue( (ControlHandle) scratchHandle);
- ((SaveCopyStruct*)saveDataPtr)->changeKind = kODNULL;
- GetDialogItem(theDialog, kSHLSaCKindPopupItem, &itemHit, &scratchHandle, &scratchRect);
- ODSShort kindItem = (ODSShort) GetControlValue((ControlHandle)scratchHandle);
- if (kindItem != currentKindItem)
- {
- ODType newKind = GetThisKindFromList(kindItem,
- ((SaveCopyStruct*)saveDataPtr)->kindList);
- ((SaveCopyStruct*)saveDataPtr)->changeKind = newKind;
- }
-
- break;
- }
-
- return (item);
- }
-
- ODBoolean RealShell::AskUserWhereToPutIt( ODDraft* whichDraft, Str255 defaultName,
- Str255 msg, StandardFileReply* reply )
- {
- Point pt;
- SetPt(&pt, 0, 0);
-
- ODBoolean makeStationery;
-
- ODSLong savedRefNum;
- // Setup fSaveCopyData fields for custom put file
- fSaveCopyData = new SaveCopyStruct;
-
- fSaveCopyData->session = this->GetSession();
- TempODPart rootPart = ODAcquireRootPartOfDraft(fEV, whichDraft);
-
- // This should probably use a frame, otherwise we're ignoring the disk file
- fSaveCopyData->makeStationery = kODFalse; // always default to saving a document
-
- fSaveCopyData->partKind = ODGetKind(fEV, rootPart );
- fSaveCopyData->kindList =
- fSession->GetStorageSystem(fEV)->CreateTypeList(fEV, kODNULL);
-
- // get StorageUnit kinds
- ContentValueTypes(rootPart->GetStorageUnit(fEV), fSaveCopyData->kindList);
-
- // get all kinds supported by this editor
- ODNameSpaceManager* nsm = fSaveCopyData->session->GetNameSpaceManager(fEV);
- ODEditor editorID = GetCurrentEditorForPart(rootPart);
- GetAllKindsForEditor(nsm, fSaveCopyData->kindList, editorID);
- ODDisposePtr(editorID);
-
- BeginUsingLibraryResources(savedRefNum);
- fSaveCopyData->iconUPP = NewUserItemProc(DrawSmallIcon);
- DlgHookYDUPP saveACopyUPP = NewDlgHookYDProc(SaveCopyDlgHook);
-
- fWindowState->DeactivateFrontWindows(fEV);
-
- {
- TempODMenuBar currentMenuBar = fWindowState->AcquireCurrentMenuBar(fEV);
- ODDialogBegin(fEV, fSession, currentMenuBar, kODNULL);
- CustomPutFile(msg, defaultName, reply,
- kSHLSaveCopyDlgID, pt, saveACopyUPP, kODNULL, kODNULL , kODNULL, fSaveCopyData);
- ODDialogEnd();
- }
-
- fWindowState->ActivateFrontWindows(fEV);
-
- DisposeRoutineDescriptor(saveACopyUPP);
- DisposeRoutineDescriptor(fSaveCopyData->iconUPP);
- EndUsingLibraryResources(savedRefNum);
-
- makeStationery = fSaveCopyData->makeStationery;
-
- ODDisposePtr( fSaveCopyData->partKind );
- ODDeleteObject( fSaveCopyData->kindList );
- ODDeleteObject( fSaveCopyData );
-
- return makeStationery;
- }
-
- void RealShell::SaveACopy(ODDraft* draft)
- {
- // save a copy of the topmost draft into a new container
- StandardFileReply reply;
-
- Str255 msg;
-
- ODDocument* document = draft->GetDocument(fEV);
-
- Str255 fileName;
- ODGetDocumentFileName(fEV, document, (char*)&(fileName[0]));
- CToPascalString((char*)fileName);
-
- Str255 defaultName;
-
- // HI$ #1247070: should we append " Draft <n>" if the user happens to be saving
- // a copy of a draft?
-
- { CUsingLibraryResources r;
- GetIndString(msg, kSHLStrsID, kSHLStrIndDSaveACopy);
- ReplaceIntoString(kSHLCopyDefaultStrID, fileName, kODEmptyPString, defaultName);
- }
- if (defaultName[0] > kODMaxFileNameSize)
- ClipStringToBytes( defaultName, kODMaxFileNameSize, smCurrentScript );
-
- ODBoolean isStationery =
- this->AskUserWhereToPutIt(draft, defaultName, msg, &reply );
- if (!reply.sfGood)
- return;
-
- TempPlatformFile file = new PlatformFile();
- file->Specify(&reply.sfFile);
-
- TempPlatformFile
- currentFile = GetPlatformFileFromContainer(fEV, document->GetContainer(fEV));
-
- if (reply.sfReplacing)
- {
- ODBoolean isEqual = file->IsEqualTo(currentFile);
-
- if (isEqual != kODFalse)
- {
- THROW(kODErrCannotSaveACopyOntoCurrentDoc);
- }
-
- TRY
- file->Delete();
- CATCH_ALL
- THROW(kODErrCannotSaveACopyOntoBusyDoc);
- ENDTRY;
- }
-
- ODSaveACopyOfDraft(fEV, fSession, draft, file);
- file->SetStationery(isStationery);
- CopyResources(currentFile, file); // copy the resource over to the new copy
- }
-
-
- //------------------------------------------------------------------------------
- // InitKindsPopup $$$$$ copied from Info.cpp, can this be factored? $Opt
- //------------------------------------------------------------------------------
-
- ODStatic void InitKindsPopup ( ODTypeList* kindList,
- ODType theKind,
- ControlHandle itemHandle,
- ODSShort* currentKindItem,
- MenuHandle kindMenu,
- ODSShort* translateItem,
- ODSession* session )
- {
- ODSShort item = 1;
-
- Environment* ev = somGetGlobalEnvironment();
-
- ODUShort i;
-
- for (i = CountMItems(kindMenu) - 1; i > 0; --i)
- {
- DeleteMenuItem(kindMenu, i);
- }
-
- AddTypesToMenu(kindList, kindMenu, session);
-
- {
- for( TempODTypeListIterator kindIter(ev ,kindList); kindIter.Current(); kindIter.Next(), item++ )
- {
- ODBoolean isEqual = ODISOStrEqual(kindIter.Current(), theKind);
- if ( isEqual )
- break;
- }
- }
-
- EnableItem(kindMenu, *translateItem);
- *translateItem = kindList->Count(ev)+1;
-
- SetControlMinimum(itemHandle, 1);
- SetControlMaximum(itemHandle, *translateItem);
- SetControlValue(itemHandle, item);
- *currentKindItem = item;
-
-
- // Determine if translation is an option
- ODTypeList* translateToList =
- session->GetStorageSystem(ev)->CreateTypeList(ev, kODNULL);
-
- TRY
- GetDestinationKindsList(kindList, translateToList, kODNULL, session);
- if ( translateToList->Count(ev) == 0 )
- DisableItem(kindMenu, *translateItem);
- CATCH_ALL
- DisableItem(kindMenu, *translateItem);
- ENDTRY
-
- delete translateToList;
- }
-
- //-------------------------------------------------------------------------------------
- // Revert
- //-------------------------------------------------------------------------------------
-
-
- void RealShell::Revert(ODDocument* document)
- {
- if (this->DoesUserOKRevert(document))
- {
- ODRevertDocument(fEV, fSession, document);
- }
- }
-
- ODBoolean RealShell::DoesUserOKRevert(ODDocument* document)
- {
- // asks user "Revert to the last saved version?"
-
- ArrowCursor();
-
- char fileName[256];
- ODGetDocumentFileName(fEV, document, &(fileName[0]));
- CToPascalString(fileName);
-
- ODSLong savedRefNum;
- BeginUsingLibraryResources(savedRefNum);
-
- ParamText(kODEmptyPString, (unsigned char const *)fileName,
- kODEmptyPString, kODEmptyPString);
-
- fWindowState->DeactivateFrontWindows(fEV);
-
- ODSShort btnClicked;
- TRY
- {
- DialogPtr askRevertDlg = kODNULL;
- askRevertDlg = ODGetNewDialog( fEV, kSHLsvRevert, fSession, kODTrue );
- THROW_IF_NULL( askRevertDlg );
- ODUseCommandKeyStringsResource( kSHLsvRevertCmdKeyStrs );
- ::ShowWindow( askRevertDlg );
- ::ModalDialog( GetODButtonKeyFilterProc(), &btnClicked );
- ::DisposeDialog( askRevertDlg );
- }
- CATCH_ALL
- {
- btnClicked = kSHLscCancel; // Cancel the revert
- }
- ENDTRY;
-
- fWindowState->ActivateFrontWindows(fEV);
-
- EndUsingLibraryResources(savedRefNum);;
- return kSHLscOK == btnClicked;
- }
-
-
- //-------------------------------------------------------------------------------------
- // Drafts
- //-------------------------------------------------------------------------------------
-
- void RealShell::Drafts(ODDocument* document)
- {
- ODDraft* topDraft = ODGetTempDraftFromOpenDocument(fEV, fSession, document);
- if (topDraft)
- topDraft->Acquire(fEV);
- else
- topDraft = document->AcquireDraft(fEV,kODDPReadOnly,0,kODNULL,kODPosTop,kODFalse);
-
- DraftWindow* d = new DraftWindow;
- DraftWinAction dWinAction = kDraftWinNone;
- ODDraft* curDraft = kODNULL;
- d->InitDraftWindow(fEV, topDraft);
-
- fWindowState->DeactivateFrontWindows(fEV);
- ArrowCursor();
- do {
- dWinAction = d->Drafts(fEV, curDraft, dWinAction, ODDraftHasWriteAccess(fEV, topDraft));
- switch (dWinAction) {
- case kDraftWinCreate:
- WASSERT(ODDraftHasWriteAccess(fEV, topDraft));
- fWindowState->ActivateFrontWindows(fEV);
- d->DraftSaved(fEV, topDraft);
- ODSaveDocument(fEV, fSession, document);
- ODCloseDraft(fEV, fSession, topDraft);
- #ifdef ODDebug
- ODULong topDraftRefCount = topDraft->GetRefCount(fEV);
- WASSERT(topDraftRefCount == 2);
- #endif
- topDraft->Release(fEV); // to balance the CreateDraft when the document was opened
- topDraft = document->CreateDraft(fEV, topDraft, kODTrue);
- // This CreateDraft call is doing two things with refcounts.
- // First, it is releasing topDraft which balances the Acquire at the top of
- // this function.
- // Second, it is creating a new temp draft, which puts us in the same
- // state as we were before the above topDraft->Release, except
- // for the need to Reacquire the topDraft as was done at the top of this
- // function which we do in the next statement.
- topDraft->Acquire(fEV);
-
- ODTempDraftCreated(fEV, fSession, document, topDraft);
- curDraft = topDraft;
-
- {
- TempODStorageUnit su = topDraft->AcquireDraftProperties(fEV);
- ODResetDateModByInfo(fEV, su);
- }
-
- d->InitDraftWindow(fEV, topDraft);
- ODOpenDraft(fEV, fSession, topDraft);
- ODSaveDocument(fEV, fSession, document);
- fWindowState->DeactivateFrontWindows(fEV);
-
- break;
- case kDraftWinDelete:
- ODDraft* selDraft = d->GetSelectedDraft();
-
- ODCloseDraft(fEV, fSession, selDraft);
- ODReleaseObject( fEV, selDraft ); // -- TÇ: was acquired in draftswindow
-
- d->DeleteSelectedDraft(fEV, fSession);
- break;
- }
- } while (dWinAction == kDraftWinDelete);
-
- fWindowState->ActivateFrontWindows(fEV);
-
- if (dWinAction == kDraftWinOpen)
- {
- // open selected Drafts as additional root windows within this process
- // if a particular draft already has a window, bring it to front, don't create a new one
- ODDraft* selDraft = d->GetSelectedDraft();
- WASSERT(selDraft);
-
- ODOpenDraft(fEV, fSession, selDraft);
- }
- ODDeleteObject(d);
- ODReleaseObject( fEV, topDraft ); // balances Acquire & AcquireDraft at beginning.
-
- if ( dWinAction == kDraftWinLowMemAbort )
- THROW( kODErrOutOfMemory );
- }
-
- //-------------------------------------------------------------------------------------
- // Info
- //-------------------------------------------------------------------------------------
-
-
- void RealShell::DocumentInfo(ODDocument* document)
- {
- ODUnused(document);
-
- ODDocumentInfo(fEV, fSession);
- }
-
- /*
- // Default implementation for active parts which do nothing. Keep this code -TÇ.
- void RealShell::PartInfo()
- {
- ArrowCursor();
- ODTypeToken selectionFocus = fSession->Tokenize(fEV, kODSelectionFocus);
- TempODFrame activeFrame = fSession->GetArbitrator(fEV)->AcquireFocusOwner(fEV, selectionFocus);
- ODFrameFacetIterator* facets = activeFrame->CreateFacetIterator(fEV);
- fSession->GetInfo(fEV)->ShowPartFrameInfo(fEV, facets->First(fEV),
- this->HasWriteAccess());
- ODDeleteObject(facets);
- }
- */
-
- //-------------------------------------------------------------------------------------
- // Error Handling
- //-------------------------------------------------------------------------------------
-
- void RealShell::ExceptionAlert(ODError exceptionCode, const char message[])
- {
- Str255 errStr;
-
- if ( gODBentoFatalErrorHasOccurred )
- ODBentoFatalError();
-
- // Errors not to display:
- if( exceptionCode == kODNoError || exceptionCode == kODErrAlreadyNotified
- || exceptionCode == userCanceledErr )
- return;
-
- // If interaction is allowed, notify user until process is activated:
- if( AEInteractWithUser(kNoTimeOut,kODNULL,kODNULL) != noErr )
- return;
-
- TRY{
-
- CUsingLibraryResources r;
-
- ODBoolean lowMem = ! this->CheckFreeMemory();
-
- TRY{
- if (fWindowState)
- fWindowState->DeactivateFrontWindows(fEV);
- }CATCH_ALL{
- WARN("Error %d deactivating front windows",ErrorCode());
- // don't reraise
- }ENDTRY
-
- LookupErrString(exceptionCode, kODErrUserID, errStr);
- if ( fFailedPlugInName[0] != 0 )
- {
- ReplaceIntoString( kSHLPlugInErrorStrID, fFailedPlugInName, errStr, errStr);
- fFailedPlugInName[0] = 0;
- }
-
- #if ODDebug
- ParamText(errStr, "\pOption-click OK for more…", kODEmptyPString, kODEmptyPString);
- // NOTE: This hard coded string is ok because it is for debugging only. -TC
- #else
- ParamText(errStr, kODEmptyPString, kODEmptyPString, kODEmptyPString);
- #endif
-
- // Do not use a filter-proc if low on memory since it calls back to OpenDoc!
- ModalFilterUPP filter = lowMem ?kODNULL :GetODButtonKeyFilterProc();
-
-
- // Shazam! Show the alert:
- ShowAlert(fEV, kSHLphGenError, filter, fSession);
-
- TRY{
- if (isOptionKeyDown())
- {
- Str255 debugStrString;
- debugStrString[0] = 0;
-
- GetIndString(debugStrString, kSHLStrsID, kSHLStrIndDException);
-
- Str255 tempString;
-
- NumToString(exceptionCode, tempString);
- if (debugStrString[0] + tempString[0] <= 255)
- ConcatPascalStrings(debugStrString, tempString);
-
- LookupErrString(exceptionCode, kODErrSupportID, errStr);
-
- char msg[256];
- if( message ) {
- strncpy(msg,message,255);
- msg[255] = 0;
- c2pstr(msg);
- } else
- msg[0] = 0;
-
- ParamText(errStr, debugStrString, (StringPtr)msg, kODEmptyPString);
- ShowAlert(fEV, kSHLphGenError, filter, fSession);
- }
- }CATCH_ALL{
- WARN("Error %d handling opt key down",ErrorCode());
- // don't reraise
- }ENDTRY
-
- #ifdef SHLTestErrorDialogUsage
- SHLDebugStr("\pPostErrorDialog HeapInfo…");
- HeapInfo();
- #endif
-
- TRY{
- if (fWindowState)
- fWindowState->ActivateFrontWindows(fEV);
- }CATCH_ALL{
- WARN("Error %d re-activating front windows",ErrorCode());
- // don't reraise
- }ENDTRY
-
- ResetAlertStage();
-
- }CATCH_ALL{
- SysBeep(3);
- WARN("Error %d thrown by exception alert",ErrorCode());
- // Eat exception, don't reraise
- }ENDTRY
-
- if( exceptionCode == kODErrFatalContainerError )
- fSession->GetDispatcher(fEV)->Exit(fEV); // Fatal error means we must quit!
- }
-
- //----------------------------------------------------------------------------------------
- // SearchErrTable: Private function
- //----------------------------------------------------------------------------------------
-
- ODBoolean RealShell::SearchErrTable(ODError value,
- ODResNumber resourceID,
- Str255 str)
- {
- ErrRecordHandle table;
-
- str[0] = 0;
- ODSLong savedRefNum;
- BeginUsingLibraryResources(savedRefNum);
- table = (ErrRecordHandle)GetResource('errs', resourceID);
- DetachResource((Handle)table);
- EndUsingLibraryResources(savedRefNum);
-
- if (table)
- {
- short lenTab;
- ODResNumber strID = 0;
- SignedByte savedState = HGetState((Handle)table);
- HLock((Handle)table);
-
- ErrRecordPointer pEntry = *table;
-
- lenTab = (short)(GetHandleSize((Handle)table) / sizeof(ErrRecord));
- for (short i = 1; i <= lenTab; ++i, ++pEntry)
- {
- if (pEntry->lowErr == 0)
- strID = (ODResNumber)(pEntry->index); // WARNING: assigning an ODULong to a short
- else if ((pEntry->lowErr <= value) && (value <= pEntry->highErr))
- {
- if (pEntry->index > 0)
- {
- ODSLong savedRefNum;
- BeginUsingLibraryResources(savedRefNum);
- GetIndString(str, strID, (ODResNumber)(pEntry->index)); // WARNING: passing in an ODULong as a short
- EndUsingLibraryResources(savedRefNum);;
- }
- return kODTrue;
- }
- }
- HSetState((Handle)table, savedState);
- }
- return kODFalse;
- } // SearchErrTable
-
-
- //----------------------------------------------------------------------------------------
- // LookupErrString:
- //----------------------------------------------------------------------------------------
- ODBoolean RealShell::LookupErrString(ODError value,
- ODResNumber resourceID,
- Str255 str)
- {
- if (SearchErrTable(value, 0/*errAppTable*/ + resourceID, str))
- return kODTrue;
- else
- return SearchErrTable(value, resourceID, str);
- } // LookupErrString
-
- //----------------------------------------------------------------------------------------
- // CreateDefaultIText:
- //----------------------------------------------------------------------------------------
- // <eeh> this might be more useful in IText.cpp or whatever it's called.
- static ODIText* CreateDefaultIText(StringPtr text)
- {
- ODScriptCode script = FontToScript( GetSysFont() );;
- ODLangCode lang = GetScriptVariable(script, smScriptLang);
- return CreateITextPString( script, lang, text);
- }
-
- /*********************************************************************************
- SendFinderODOCEvent
- Temporary function that should be merged with Jens's CreateFinderRevealEvent in
- WinPopM.cpp (UI subsystem). Or perhaps we needn't bother, since this is just
- a workaround anyway.
- *********************************************************************************/
-
- static OSErr SendFinderODOCEvent( const FSSpec *fileToOpen )
- {
- const DescType kFinderSignature = 'MACS';
- const DescType kFinderEventClass = 'FNDR';
-
- OSErr err;
- OSType finderSignature = kFinderSignature;
- AliasHandle alias = NULL;
- AEDesc target = NULL_DESCRIPTOR_DEFINITION;
- AEDescList list = NULL_DESCRIPTOR_DEFINITION;
-
- AppleEvent openEvent = NULL_DESCRIPTOR_DEFINITION;
-
- err= AECreateDesc(typeApplSignature,&finderSignature,sizeof(OSType), &target);
- if( err ) goto exit;
- err= AECreateAppleEvent( kCoreEventClass, kAEOpenDocuments, &target,
- kAutoGenerateReturnID, kAnyTransactionID, &openEvent );
- if( err ) goto exit;
- // AEDisposeDesc(&target);
- err= NewAliasMinimal( fileToOpen, &alias );
- if( err ) goto exit;
-
- err= AECreateList(NULL,0,false, &list);
- if( err ) goto exit;
- err= AEPutPtr(&list,1,typeAlias,*alias,GetHandleSize((Handle)alias));
- if( err ) goto exit;
-
- err= AEPutParamDesc(&openEvent, keyDirectObject, &list);
- if( err ) goto exit;
-
- err = AESend( &openEvent, kODNULL,
- kAENoReply|kAEAlwaysInteract|kAECanSwitchLayer,
- kAENormalPriority, kNoTimeOut, kODNULL, kODNULL );
-
- exit:
- AEDisposeDesc(&target);
- AEDisposeDesc(&list);
- if( alias ) DisposeHandle((Handle)alias);
- // if( err )
- AEDisposeDesc(&openEvent);
-
- return err;
- }
-